为什么set_xticks不设置刻度线标签? [英] Why set_xticks doesn't set the labels of ticks?

查看:558
本文介绍了为什么set_xticks不设置刻度线标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

我希望xlabs为101, 102 ... 但是,如果我切换为使用plt.xticks(x, [i+100 for i in x])并显式重写该函数,那么它将起作用.

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.

推荐答案

.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])

这篇关于为什么set_xticks不设置刻度线标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆