2015-11-06 53 views
2

我总是使用ser.plot(xticks=range(0, len(ser), step), ..)来绘制指定xticks的图形。但是,在带有标签的Series时,它在熊猫0.17中不起作用。下面是代码:这是熊猫0.17中`Series.plot`的bug吗?

In [1]: from numpy import random as rnd 
In [2]: import pandas as pd 
In [3]: pd.__version__ 
Out[3]: '0.17.0' 
In [4]: %matplotlib inline 
In [5]: rnd.seed(123) 
In [6]: ser = pd.Series(rnd.randn(73).cumsum(), index=['P%02d' % i for i in range(73)]) 
In [7]: ser.plot(figsize=(9, 6), rot=60, title='Figure without xticks') 
Out[7]: <matplotlib.axes._subplots.AxesSubplot at 0x8370198 

enter image description here

In [8]ser.plot(figsize=(9, 6), xticks=list(range(0, 73, 6)), rot=60, title='Figure with xticks') 
Out[8]: <matplotlib.axes._subplots.AxesSubplot at 0x83e9940> 

enter image description here

而在熊猫0.16同一代码:

In [1]: from numpy import random as rnd 
In [2]: import pandas as pd 
In [3]: pd.__version__ 
Out[3]: '0.16.0' 
In [4]: %matplotlib inline 
In [5]: rnd.seed(123) 
In [6]: ser = pd.Series(rnd.randn(73).cumsum(), index=['P%02d' % i for i in range(73)]) 
In [8]: ser.plot(figsize=(9, 6), xticks=list(range(0, 73, 6)), rot=60, title='Figure with xticks') 
Out[8]: <matplotlib.axes._subplots.AxesSubplot at 0xbbf19b0> 

enter image description here

回答

3

这确实是0.17.0中的一个回归,并且将固定在0.17.1(参见https://github.com/pydata/pandas/pull/11531)。

如果你需要现在的解决方法(至0.17.1被释放或防止你需要降级),您可以:

  • 手动创建的情节后调整ticklabels:

    ax.set_xticklabels(['P%02d' % i for i in ax.get_xticks()]) 
    
  • 或应用在大熊猫代码补丁(见上面的链接,这只是一个行变化)