+2 votes
in Programming Languages by (75.1k points)
By default, matplotlib library puts numbers on x-axis ticks. I want to name the ticks on x-axis .e.g Jan, Feb, etc. How can I do that?

1 Answer

+1 vote
by (353k points)
selected by
Best answer

You can use 'set_xticklabels()' to change those tick numbers to your desired values. See the following example.

import numpy as np

import matplotlib.pyplot as plt

from textwrap import wrap

y = [2.6,3.5,1.8,2.4,3.9]

x = np.arange(len(y))

fig, ax = plt.subplots()

title = 'Test Plot'




plt.title(title, fontsize=13)


 Change numbers on x-axis in matplotlib

by (353k points)
'xticks()' can also be used as follows:

x = ['aa','bb','cc','dd','ee']
plt.xticks(np.arange(len(x)), x, rotation=0)