Why set_xticks doesn't set the labels of ticks?

匿名 (未验证) 提交于 2019-12-03 02:05:01

问题:

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.

回答1:

.set_xticks() on the axes will set the locations and set_xticklabels() will set the displayed text.

def test(axes):     axes.bar(x,y)     axes.set_xticks(x)     axes.set_xticklabels([i+100 for i in x]) 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!