Pandas数据帧的Log-Log图

时间:2014-05-28 13:26:03

标签: python 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)    

df1.plot(logy=True, logx=True)

如何使x轴对数?

1 个答案:

答案 0 :(得分:8)

尝试使用pandas plot功能创建对数日志图时,您必须在关键字参数中选择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()

Plot