私信  •  关注

Deninhos

Deninhos 最近创建的主题
Deninhos 最近回复了
8 年前
回复了 Deninhos 创建的主题 » Python帮助-设置x限制的间隔[duplicate]

我想出了一个不雅的解决办法。考虑到我们有X轴和X.中每个点的标签列表。

例子:
import matplotlib.pyplot as plt

x = [0,1,2,3,4,5]
y = [10,20,15,18,7,19]
xlabels = ['jan','feb','mar','apr','may','jun']
假设我只想给'feb'和'jun'显示ticks标签
xlabelsnew = []
for i in xlabels:
    if i not in ['feb','jun']:
        i = ' '
        xlabelsnew.append(i)
    else:
        xlabelsnew.append(i)
很好,现在我们有一份假标签清单。首先,我们绘制了原始版本。
plt.plot(x,y)
plt.xticks(range(0,len(x)),xlabels,rotation=45)
plt.show()
现在,修改版。
plt.plot(x,y)
plt.xticks(range(0,len(x)),xlabelsnew,rotation=45)
plt.show()