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

+2 votes
by (349k points)
selected by
 
Best answer

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()

 

+1 vote
by
edited by anonymous
Thank you so much

...