+2 votes
in Programming Languages by (14.6k 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

0 votes
by (25.6k points)

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)



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

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