我正在尝试使用内置的pandas.DataFrame.plot
函数进行简单的绘图(我想避免使用完整的pyplt
图形/轴对象设置方法)。但是,当我没有指定x轴范围参数(xlim
)时,我得到奇怪的结果。您会认为plot
会根据数据的最大值和最小值选择默认值。
(我在使用Python 2.7的Jupyter笔记本中使用内联绘图)
设置代码
import numpy as np
import pandas as pd
%matplotlib inline
n = 366
x = 10.0*np.random.randn(n)
time_series = pd.date_range("2016-01-01", "2016-12-31")
df = pd.DataFrame(data=x, index=time_series, columns=['X'])
df['y'] = 100 + 2.5*x + 5.0*np.random.randn(n)
df.describe()
以下是数据的样子:
所需代码:
df.plot('X', 'y', style='.')
这是我期望得到的:
df.plot('X', 'y', xlim=(-35, 35), style='.')
每次运行代码时,我都会得到一个奇怪的默认轴范围选择。