2013-12-08 17 views
3

pandas documentation告訴我,pandas.DataFrame.boxplot()返回一個matplotlib.axes.AxesSubplot,但我似乎得到一個字典...我誤解文檔或以某種方式混淆了嗎?如何使用pandas.DataFrame.boxplot的返回值?

我希望能夠改變我的軸標籤,因爲當前的文字有點長且笨拙,可能會對其進行釣魚。 I can see that I could do this entirely in matplotlib,但想知道是否可以使用boxplot()的返回值在熊貓中做到這一點?

代碼:

ax_subpl = d.boxplot(SHARING_FIELDS, grid=False) 
print(type(ax_subpl)) 

輸出:

<class 'dict'> 

感謝。

回答

4

文檔字符串在這裏有誤導。您應該在Github page上提出問題。

請記住,df.boxplot需要rot參數,因此您可以在創建時指定該參數。 不幸的是,它看起來並不像箱線圖返回軸:

In [45]: df = DataFrame(rand(10,5)) 

In [46]: bp = df.boxplot(rot=45) 

In [47]: bp 
Out[47]: 
{'boxes': [<matplotlib.lines.Line2D at 0x111f53a50>, 
    <matplotlib.lines.Line2D at 0x111f5dc10>, 
    <matplotlib.lines.Line2D at 0x111f68e50>, 
    <matplotlib.lines.Line2D at 0x111f740d0>, 
    <matplotlib.lines.Line2D at 0x111f7d310>], 
'caps': [<matplotlib.lines.Line2D at 0x111f4eb50>, 
    <matplotlib.lines.Line2D at 0x111f4ecd0>, 
    <matplotlib.lines.Line2D at 0x111f5af50>, 
    <matplotlib.lines.Line2D at 0x111f5d5d0>, 
    <matplotlib.lines.Line2D at 0x111f681d0>, 
    <matplotlib.lines.Line2D at 0x111f68810>, 
    <matplotlib.lines.Line2D at 0x111f72410>, 
    <matplotlib.lines.Line2D at 0x111f72a50>, 
    <matplotlib.lines.Line2D at 0x111f7a650>, 
    <matplotlib.lines.Line2D at 0x111f7ac90>], 
'fliers': [<matplotlib.lines.Line2D at 0x111f58710>, 
    <matplotlib.lines.Line2D at 0x111f5a110>, 
    <matplotlib.lines.Line2D at 0x111f608d0>, 
    <matplotlib.lines.Line2D at 0x111f60ed0>, 
    <matplotlib.lines.Line2D at 0x111f6bb10>, 
    <matplotlib.lines.Line2D at 0x111f6e510>, 
    <matplotlib.lines.Line2D at 0x111f74d50>, 
    <matplotlib.lines.Line2D at 0x111f77750>, 
    <matplotlib.lines.Line2D at 0x111f7df90>, 
    <matplotlib.lines.Line2D at 0x111f80990>], 
'medians': [<matplotlib.lines.Line2D at 0x111f580d0>, 
    <matplotlib.lines.Line2D at 0x111f60290>, 
    <matplotlib.lines.Line2D at 0x111f6b4d0>, 
    <matplotlib.lines.Line2D at 0x111f74710>, 
    <matplotlib.lines.Line2D at 0x111f7d950>], 
'whiskers': [<matplotlib.lines.Line2D at 0x111f4eed0>, 
    <matplotlib.lines.Line2D at 0x111f4e7d0>, 
    <matplotlib.lines.Line2D at 0x111f5a710>, 
    <matplotlib.lines.Line2D at 0x111f5a910>, 
    <matplotlib.lines.Line2D at 0x111f638d0>, 
    <matplotlib.lines.Line2D at 0x111f63b50>, 
    <matplotlib.lines.Line2D at 0x111f6eb10>, 
    <matplotlib.lines.Line2D at 0x111f6ed90>, 
    <matplotlib.lines.Line2D at 0x111f77d50>, 
    <matplotlib.lines.Line2D at 0x111f77fd0>]} 

您可以選擇的線路之一,並調用get_axes()方法得到阿霍德的軸:

In [48]: ax = bp['boxes'][0].get_axes() 

In [49]: ax 
Out[49]: <matplotlib.axes.AxesSubplot at 0x111ed1f50> 

,並繼續從那裏做你的格式。

+0

感謝您的迴應 - 我會試驗這個。 – Saff

+0

這是現貨,謝謝。 – Saff