Pandas数据帧图的异常轴范围

时间:2017-03-19 18:48:44

标签: pandas matplotlib dataframe axes

我正在尝试使用内置的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()

以下是数据的样子:

enter image description here

所需代码:

df.plot('X', 'y', style='.')

以下是我从上面的代码中获得的内容: enter image description here

这是我期望得到的:

df.plot('X', 'y', xlim=(-35, 35), style='.')

enter image description here

每次运行代码时,我都会得到一个奇怪的默认轴范围选择。

0 个答案:

没有答案