Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用matplotlib模块pyplot在x/y标签中放置变量_Python_Label_Matplotlib_Python 3.2 - Fatal编程技术网

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

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_

我正在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

如果我没弄错,你可以试试:

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
?谢谢。我不认为它会工作,这就是为什么我没有测试。