Python 为什么 set_xticks 不设置刻度的标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21910986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why set_xticks doesn't set the labels of ticks?
提问by colinfang
import pylab as plt
x = range(1, 7)
y = (220, 300, 300, 290, 320, 315)
def test(axes):
axes.bar(x,y)
axes.set_xticks(x, [i+100 for i in x])
a = plt.subplot(1,2,1)
test(a)
b = plt.subplot(1,2,2)
test(b)


I am expecting the xlabs as 101, 102 ...However, if i switch to use plt.xticks(x, [i+100 for i in x])and rewrite the function explicitly, it works.
我期待 xlabs101, 102 ...但是,如果我切换到使用plt.xticks(x, [i+100 for i in x])并显式重写该函数,它就可以工作。
采纳答案by Hooked
.set_xticks()on the axes will set the locations and set_xticklabels()will set the displayed text.
.set_xticks()在轴上将设置位置并set_xticklabels()设置显示的文本。
def test(axes):
axes.bar(x,y)
axes.set_xticks(x)
axes.set_xticklabels([i+100 for i in x])



![Python 如何从 RDD[PYSPARK] 中删除重复值](/res/img/loading.gif)