1

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.

2

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

perfect. Just one more question: how can the labels be transposed vertically in this setup?
many thanks. wouldn't have expected it to be that short. I noticed that you get the vertical labels as well when you set rot=90 in the initial answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.