如何使用matplotlib模块pyplot将变量放在x/y标签中

Atu*_*ana 3 python label matplotlib python-3.2

我在Python3.2中使用'Matplotlib'模块'pyplot'生成堆积条形图.唯一的问题是,在'xlabel'中,我必须为分析的条目数包含一个变量(整数).我已经尝试了很多但是找不到在xlabel中包含变量的方法.

我的部分代码:

plt.ylabel('Percentage', fontproperties=font_manager.FontProperties(size=10))
plt.xlabel('position', fontproperties=font_manager.FontProperties(size=10))
plt.title("'Graph-A",fontproperties=font_manager.FontProperties(size=10))

plt.xticks(np.arange(22), np.arange(1,23), fontproperties=font_manager.FontProperties(size=8))
plt.yticks(np.arange(0,121,5), fontproperties=font_manager.FontProperties(size=8))
plt.legend((p1[0], p2[0], p3[0], p4[0],p5[0]), ('A','B','C','D','E'), loc=1, prop=font_manager.FontProperties(size=7))
Run Code Online (Sandbox Code Playgroud)

变量'entries'保存已处理条目的值,我需要在xlabel中包含此值.请帮忙?

AK

Har*_*pal 6

如果我找对你,你可以尝试:

plt.xlabel('position %d' % entries, fontproperties=font_manager.FontProperties(size=10))
Run Code Online (Sandbox Code Playgroud)