+2 votes
in Programming Languages by (17.0k 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 (28.9k 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.set_xticklabels(['aa','bb','cc','dd','ee'], rotation=45)

plt.title(title, fontsize=13)



0 votes
edited by anonymous
Thank you so much