从熊猫数据框绘制条形图

时间:2016-11-13 13:01:58

标签: python pandas matplotlib

我有以下pandas数据框,我想在matplotlib中将NaNhigh值绘制为bar plot

df

               Close 1   Close 2   Close 3   Close 4   Close 5   Close 6  
Index                                                               
NaN            0.000348  0.000975  0.001450  0.001923  0.002483  0.002916   
high           0.001416 -0.000215  0.000058  0.000026 -0.000766 -0.000255

x轴上的标签应为列名。怎么办呢?

非常感谢提前。

1 个答案:

答案 0 :(得分:1)

你可以绘制转置的DF:

In [9]: import matplotlib
   ...: matplotlib.style.use('ggplot')
   ...:

In [10]: df.T.plot.bar(rot=0)
Out[10]: <matplotlib.axes._subplots.AxesSubplot at 0xa1ae240>

enter image description here

带垂直标签的

In [14]: df.T.plot.bar(width=0.85, alpha=0.6, figsize=(14,12))
Out[14]: <matplotlib.axes._subplots.AxesSubplot at 0xa3499e8>

enter image description here