pandas 熊猫数据框的对数图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23912912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:05:40 来源:igfitidea点击:
Log-Log plot of pandas dataframe
提问by sjdh
I would like to make a log-log plot with pandas
我想用Pandas制作对数图
import numpy as np
import pandas as pd
x = 10**arange(1, 10)
y = 10** arange(1,10)*2
df1 = pd.DataFrame( data=y, index=x )
df2 = pd.DataFrame(data = {'x': x, 'y': y})
df1.plot(logy=True, logx=True)


How can I make the x-axis logarithmic?
如何使 x 轴成为对数?
回答by Ffisegydd
When trying to create a log-log plot using the pandasplotfunction you must select loglog=Truerather than logx=True, logy=Truewithin your keyword-arguments.
尝试使用pandasplot函数创建 log-log 图时,您必须选择loglog=True而不是logx=True, logy=True在关键字参数中。
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
x = 10 ** np.arange(1, 10)
y = 10 ** np.arange(1, 10) * 2
df1 = pd.DataFrame(data=y, index=x)
df1.plot(loglog=True, legend=False)
plt.show()



