Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a variable in x/y label using matplotlib module pyplot

I am generating a stacked bar graph in Python3.2 and using 'Matplotlib' module 'pyplot'. The only problem is that in the 'xlabel' I have to include a variable (integer) for number of entries analyzed. I have tried a lot but could not find the way of including the variable in xlabel.

Part of my code:

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

The variable 'entries' hold the value of entries processed and I need to include this value in xlabel. Please help?

AK

like image 866
Atul Kakrana Avatar asked May 03 '12 21:05

Atul Kakrana


1 Answers

If I got you right, you could try:

plt.xlabel('position %d' % entries, fontproperties=font_manager.FontProperties(size=10))
like image 113
Harpal Avatar answered Sep 18 '22 23:09

Harpal