Poisson
Poisson

Reputation: 1623

Change the width of the Basic Bar Chart

I create a Bar Chart with matplotlib with :

import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt

objects = ('ETA_PRG_P2REF_RM', 'ETA_PRG_VDES_RM', 'ETA_PRG_P3REF_RM', 'Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
y_pos = np.arange(len(objects))
performance = [220010, 234690, 235100, 21220, 83410, 119770, 210990, 190430, 888994]
plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.ylabel('Usage')
plt.title('Programming language usage')
plt.show() 

Look at the attached Image enter image description here

But, As you can remark the width of the plot is smal, the name of object are not clear. Can you suggest me how to resolve this problem?

Thank you

Upvotes: 1

Views: 2654

Answers (1)

Mad Physicist
Mad Physicist

Reputation: 114548

You can add tick labels with a rotation:

pyplot.xticks(y_pos, objects, rotation=70)

In addition to an angle in degrees, you can specify a string:

pyplot.xticks(y_pos, objects, rotation='vertical')

You may also want to specify a horizontal alignment, especially is using an angle like 40. The default is to use the center, which makes the labels look weird:

pyplot.xticks(y_pos, objects, rotation=40, ha='right')

See the docs for a full list of options.

Upvotes: 3

Related Questions