我无法弄清楚如何减少我的情节中的多个刻度标签,同时保留刻度数。有没有办法做到这一点,或者我只能拥有与标签数量一样多的刻度?谢谢!
答案 0 :(得分:1)
设置一些滴答空标记标签。
# based on http://matplotlib.org/examples/ticks_and_spines/ticklabels_demo_rotation.html
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', '', 'Slogs']
plt.plot(x, y, 'ro')
# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels, rotation='vertical')
# Pad margins so that markers don't get clipped by the axes
plt.margins(0.2)
# Tweak spacing to prevent clipping of tick-labels
plt.subplots_adjust(bottom=0.15)
plt.show()
答案 1 :(得分:1)
回答我对Serenity的答案的评论,以下是如何获取数字标签。
x = range(100)
labels = []
for i in x:
if i % 10 == 0:
i=i
else:
i=' '
labels.append(i)
这就完成了工作。