Al_Iskander Al_Iskander - 24 days ago 11
Python Question

Plot bar chart from pandas dataframe

I have following pandas dataframe that I would like to plot the

NaN
and
high
values as a
bar plot
in matplotlib:

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


The labels on the x-axis shall be the column names. How can this be done?

Many thanks in advance.

Answer

you can plot transposed 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

with vertical labels:

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