Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate axis labels when using a matplotlib histogram?

I have a plot that looks like this, and I am trying to make the x axis labels more readable:

enter image description here

This is what I tried and the error I got:

enter image description here

like image 336
pr338 Avatar asked Dec 14 '22 00:12

pr338


1 Answers

The problem is that you are setting plt from the call to hist(), which is not what you want. It is common to import matplotlib as plt, assuming that is what was intended here:

import matplotlib.pyplot as plt

data = [1, 2, 3, 4]

p = plt.hist(data)
plt.xticks(rotation='vertical')

plt.show()

enter image description here

like image 90
Tim B Avatar answered Dec 16 '22 12:12

Tim B