旋转自定义刻度标签

使用用户定义的旋转演示自定义刻度标签。

旋转自定义刻度标签示例

  1. import matplotlib.pyplot as plt
  2. x = [1, 2, 3, 4]
  3. y = [1, 4, 9, 6]
  4. labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']
  5. plt.plot(x, y, 'ro')
  6. # You can specify a rotation for the tick labels in degrees or with keywords.
  7. plt.xticks(x, labels, rotation='vertical')
  8. # Pad margins so that markers don't get clipped by the axes
  9. plt.margins(0.2)
  10. # Tweak spacing to prevent clipping of tick-labels
  11. plt.subplots_adjust(bottom=0.15)
  12. plt.show()

下载这个示例