这是一个python数据帧后期排序绘图错误吗?

这是一个python数据帧后期排序绘图错误吗?,python,pandas,matplotlib,plot,Python,Pandas,Matplotlib,Plot,当我创建一个DataFrame,然后按列排序时,它似乎在iTreactive显示中被排序(即,repr给出的任何内容),但当我调用DataFrame.plot()函数时,它会打印未排序的数组。不过,调用matplotlib.pylab.plot效果很好。我怀疑这与聪明的指针重新排列有关,而不是传递给plot函数调用的任何函数来访问数据。。。或者我只是在做些傻事。我已经在pandas 0.8.1(osx和linux与python2.7.something)和pandas 0.9.0(osx与pyt

当我创建一个DataFrame,然后按列排序时,它似乎在iTreactive显示中被排序(即,repr给出的任何内容),但当我调用DataFrame.plot()函数时,它会打印未排序的数组。不过,调用matplotlib.pylab.plot效果很好。我怀疑这与聪明的指针重新排列有关,而不是传递给plot函数调用的任何函数来访问数据。。。或者我只是在做些傻事。我已经在pandas 0.8.1(osx和linux与python2.7.something)和pandas 0.9.0(osx与python3.something)上试过了


默认情况下,打印是数据与索引的对比。对于数字索引,请在对列进行排序后查看索引。您可能希望使用plot(使用_index=False)。见下面的例子

In [2]: df = pd.DataFrame(np.random.randn(10, 2), columns=['A', 'B'])

In [3]: df
Out[3]:
          A         B
0 -0.938196  2.220319
1 -0.022503  0.564602
2  0.033094 -0.717969
3  2.466486  1.229651
4 -0.641596 -1.016921
5  0.094125  1.531526
6  0.579631  1.398635
7 -0.854799 -0.930904
8 -1.177894 -1.501657
9  0.341655 -0.917243

In [4]: df.sort(columns='A', inplace=True)
Out[4]:
          A         B
8 -1.177894 -1.501657
0 -0.938196  2.220319
7 -0.854799 -0.930904
4 -0.641596 -1.016921
1 -0.022503  0.564602
2  0.033094 -0.717969
5  0.094125  1.531526
9  0.341655 -0.917243
6  0.579631  1.398635
3  2.466486  1.229651

In [5]: df['A'].plot(use_index=False)
Out[5]: <matplotlib.axes.AxesSubplot at 0xb56ac6c>
[2]中的
:df=pd.DataFrame(np.random.randn(10,2),columns=['A','B']
In[3]:df
出[3]:
A B
0 -0.938196  2.220319
1 -0.022503  0.564602
2  0.033094 -0.717969
3  2.466486  1.229651
4 -0.641596 -1.016921
5  0.094125  1.531526
6  0.579631  1.398635
7 -0.854799 -0.930904
8 -1.177894 -1.501657
9  0.341655 -0.917243
在[4]中:df.sort(columns='A',inplace=True)
出[4]:
A B
8 -1.177894 -1.501657
0 -0.938196  2.220319
7 -0.854799 -0.930904
4 -0.641596 -1.016921
1 -0.022503  0.564602
2  0.033094 -0.717969
5  0.094125  1.531526
9  0.341655 -0.917243
6  0.579631  1.398635
3  2.466486  1.229651
在[5]中:df['A']绘图(使用索引=False)
出[5]:

这似乎是对的。我还没有尝试过其他的可能性,但它似乎是按日期和整数索引的排序索引顺序绘制的。
In [2]: df = pd.DataFrame(np.random.randn(10, 2), columns=['A', 'B'])

In [3]: df
Out[3]:
          A         B
0 -0.938196  2.220319
1 -0.022503  0.564602
2  0.033094 -0.717969
3  2.466486  1.229651
4 -0.641596 -1.016921
5  0.094125  1.531526
6  0.579631  1.398635
7 -0.854799 -0.930904
8 -1.177894 -1.501657
9  0.341655 -0.917243

In [4]: df.sort(columns='A', inplace=True)
Out[4]:
          A         B
8 -1.177894 -1.501657
0 -0.938196  2.220319
7 -0.854799 -0.930904
4 -0.641596 -1.016921
1 -0.022503  0.564602
2  0.033094 -0.717969
5  0.094125  1.531526
9  0.341655 -0.917243
6  0.579631  1.398635
3  2.466486  1.229651

In [5]: df['A'].plot(use_index=False)
Out[5]: <matplotlib.axes.AxesSubplot at 0xb56ac6c>