Matt Pitkin
Matt Pitkin

Reputation: 6517

How do you plot an upside down histogram in matplotlib?

Can you plot a histogram in matplotlib so that it appears upside down, i.e. the base of the histogram is along the top axis and it "hangs" down? Or, alternatively, if plotting with orientation='horizontal', so that the base of the histogram is on the right hand axis?

Upvotes: 6

Views: 2783

Answers (1)

Scott Boston
Scott Boston

Reputation: 153550

Yes, use invert_yaxis:

df = pd.DataFrame({'a':[1,2,3,1,2,2,2],
             'b':[1,1,1,3,2,2,2]})
ax = df.plot.hist()
ax.invert_yaxis()

Output:

enter image description here

Upvotes: 5

Related Questions