Use the plt.xticks()
function as follows:
import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[1,2,3,4,5]
plt.bar(x,y, color='g')
plt.xlabel('x')
plt.ylabel('y')
Generate some labels to go on your graph. The list of strings must be the same length as your x
and y
lists:
LABELS = ["M","w","E","R","T"]
Plot them with the following:
plt.xticks(x, LABELS)
plt.title("Max Temperature for Months")
plt.legend()
plt.show()
See example here: http://matplotlib.org/examples/ticks_and_spines/ticklabels_demo_rotation.html
Edit: For information on adjusting the location/orientation/position of your labels, see the matplotlib api documentation, and this question: matplotlib ticks position relative to axis.
Edit: Added Image:
http://imgur.com/igjUGLb
Edit: To achieve the location and orientation that you need, you will find a great example in this question: Matplotlib Python Barplot: Position of xtick labels have irregular spaces between eachother.
Implementing:
b = plt.bar(x,y, color='g')
xticks_pos = [0.5*patch.get_width() + patch.get_xy()[0] for patch in b]
plt.xticks(xticks_pos, LABELS,rotation = 45)
gives: https://i.stack.imgur.com/arACh.jpg
Hope that helps.