1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| plt.figure(figsize=(8, 4)) # adjusting graph size / proportions
ax = freq_series.plot(kind='barh', label='Filing\nApplications', color='orange')
ax.set_title("blabla")
ax.set_xlabel("Years")
ax.set_ylabel('blabla')
ax.set_xticklabels(occ) # tickles for X axis
ax.set_yticklabels(label) # tickles for X axis
rects = ax.patches
# Rotating the xticklabels for years
for label in ax.get_xmajorticklabels():
label.set_rotation(30)
label.set_verticalalignment("top")
# Making the labels
def autolabel(rects, ax):
# Get y-axis height to calculate label position from.
(x_bottom, x_top) = ax.get_ylim()
x_height = x_top - x_bottom
for rect in rects:
height = rect.get_height()
# Fraction of axis height taken up by this rectangle
p_height = (height / x_height)
# If we can fit the label above the column, do that;
# otherwise, put it inside the column.
if p_height > 0.95: # arbitrary; 95% looked good to me.
label_position = height - (x_height * 0.05)
else:
label_position = height + (x_height * 0.01)
ax.text(rect.get_x() + rect.get_width()/2., label_position,
'%d' % int(height),
ha='right', va='bottom')
autolabel(rects, ax) |
Partager