Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在matplotlib中获得不同数量的记号和标签?_Python_Matplotlib - Fatal编程技术网

Python 如何在matplotlib中获得不同数量的记号和标签?

Python 如何在matplotlib中获得不同数量的记号和标签?,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', 'H

我不知道如何在保留刻度数量的同时减少绘图中刻度标签的数量。有没有办法做到这一点,或者我只能有和标签数量一样多的刻度?谢谢

为某些记号设置空记号标签

# 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)

这就行了。

酷!快到了!那么,我应该如何用大量数据定义这些标签(当我的标签是数字的时候)?例如,如果x=np.arange(0100,1),我希望我的标签是10,20。。。等我尝试了lables=np.arange(0100,10),但没有成功。。。谢谢你,我想了一下如何避开它。简单地通过一个可整除的if循环!