python编辑轴记号

2024-04-24 12:56:37 发布

您现在位置:Python中文网/ 问答频道 /正文

你可以看到下面的图表,这是从Jupyter。我想编辑x轴上的刻度标签,它现在很乱。这个问题只有在我添加次轴之后才会发生。它们代表从1922年到2014年的年份。我希望图表只显示每10年一次。我该怎么做

enter image description here


Tags: 编辑图表jupyter代表标签年份刻度
1条回答
网友
1楼 · 发布于 2024-04-24 12:56:37

你需要你的身体的把手才能进入轴心。下面的片段会让你每10年就有一个记号标签

import matplotlib.dates as mdates
fig, ax = plt.subplots()
 ... ... plot your things
ax.xaxis.set_major_locator(mdates.YearLocator(base=10))

相关问题 更多 >