+2 votes
in Programming Languages by (7k points)
The texts I want to put on X-axis ticks are a bit longer. How can I rotate the texts on X-axis ticks?

2 Answers

0 votes
by (13.5k points)

You need to use rotation parameter in set_xticklabels() function. Check 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'

ax.plot(x,y)

ax.set_xticks(x)

ax.set_xticklabels(['aa','bb','cc','dd','ee'], rotation=45)

plt.title(title, fontsize=13)

plt.show()

 

0 votes
by
edited by anonymous
Thank you so much
...