旋转刻度标签#

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']

fig, ax = plt.subplots()
ax.plot(x, y)
# A tick label rotation can be set using Axes.tick_params.
ax.tick_params("y", rotation=45)
# Alternatively, if setting custom labels with set_xticks/set_yticks, it can
# be set at the same time as the labels.
# For both APIs, the rotation can be an angle in degrees, or one of the strings
# "horizontal" or "vertical".
ax.set_xticks(x, labels, rotation='vertical')

plt.show()
ticklabels rotation

参考文献

此示例中显示了以下函数、方法、类和模块的使用

Sphinx-Gallery 生成的图库