matplotlib设置x轴文本间隔显示

totalSeed = df.index.tolist()
fig1, ax = plt.subplots()
ax.plot(totalSeed, df.loc[:,'MACDhist_1'])
ax.plot(df.loc[:,'MACDhist_2'])
ax.plot(df.loc[:,'MACDhist_5'])
ax.plot(df.loc[:,'MACDhist_20'])
plt.legend(loc='SouthEast')
xticks=list(range(0,len(totalSeed),40))
xlabels=[totalSeed[x] for x in xticks]
xticks.append(len(totalSeed))
xlabels.append(totalSeed[-1])
ax.set_xticks(xticks)
ax.set_xticklabels(xlabels, rotation=40)
# ax.xaxis.set_major_locator(ticker.MultipleLocator(40))
plt.title("MACDhist")

matplotlib设置x轴文本间隔显示_第1张图片

mark一下看到的其他做法:

https://blog.csdn.net/qq_37354021/article/details/82354617

你可能感兴趣的:(matplotlib设置x轴文本间隔显示)