Cyrine Ezzahra Cyrine Ezzahra - 1 month ago 5
Python Question

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], performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.title('Programming language usage')

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


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.