8

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

1
  • Just to be clear you want to pass a variable into the plt.xlabel? Commented May 3, 2012 at 23:37

3 Answers 3

10

If I got you right, you could try:

plt.xlabel('position %d' % entries, fontproperties=font_manager.FontProperties(size=10))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I didn't thought that it will work and that's why didn't tested.
3

This is what you can do in python 3.6.

plt.xlabel('Your variable is put here: {}'.format(variable))

Comments

1

You can try this. It worked for me.

plt.xlabel('position'+str(entries), fontproperties=font_manager.FontProperties(size=10))

I have used it in my code as

plt.plot(qtime,hy_p,'r.')
plt.xlabel('Time')
plt.ylabel('Hz at node '+str(50))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.