Python 如何使用matplotlib模块pyplot在x/y标签中放置变量
我正在Python3.2中生成一个堆叠条形图,并使用“Matplotlib”模块“pyplot”。唯一的问题是,在“xlabel”中,我必须包含一个变量(整数),用于分析的条目数。我已经尝试了很多,但是没有找到在xlabel中包含变量的方法 我的部分代码:Python 如何使用matplotlib模块pyplot在x/y标签中放置变量,python,label,matplotlib,python-3.2,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_
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如果我没弄错,你可以试试:
plt.xlabel('position %d' % entries, fontproperties=font_manager.FontProperties(size=10))
你可以试试这个。这对我有用
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))
这就是在Python3.6中可以做的事情
plt.xlabel('您的变量放在这里:{}.format(variable))
只是为了明确您想将变量传递到plt.xlabel
?谢谢。我不认为它会工作,这就是为什么我没有测试。