我在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))
变量'entries'保存已处理条目的值,我需要在xlabel中包含此值。请帮帮忙?
AK
答案 0 :(得分:6)
如果我找对你,你可以尝试:
plt.xlabel('position %d' % entries, fontproperties=font_manager.FontProperties(size=10))
答案 1 :(得分:0)
你可以试试这个。它对我有用。
plt.xlabel('position'+str(entries), fontproperties=font_manager.FontProperties(size=10))
我在我的代码中使用它
plt.plot(qtime,hy_p,'r.')
plt.xlabel('Time')
plt.ylabel('Hz at node '+str(50))
答案 2 :(得分:0)
这是你在python 3.6中可以做的。
plt.xlabel('Your variable is put here: {}'.format(variable))