【发布时间】:2016-08-23 02:35:41
【问题描述】:
我不知道如何在保留刻度数的同时减少绘图中的刻度数标签。有没有办法做到这一点,或者我只能有与标签数量一样多的刻度?谢谢!
【问题讨论】:
标签: python matplotlib
我不知道如何在保留刻度数的同时减少绘图中的刻度数标签。有没有办法做到这一点,或者我只能有与标签数量一样多的刻度?谢谢!
【问题讨论】:
标签: python matplotlib
为一些刻度设置空刻度标签。
# 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()
【讨论】:
只是为了回答我对 Serenity 答案的评论,以下是获取数字标签的方法。
x = range(100)
labels = []
for i in x:
if i % 10 == 0:
i=i
else:
i=' '
labels.append(i)
这样就可以了。
【讨论】: