matplotlib - How to set more margins -
i have pyplot code.
since want group multiple bars, trying write text in graph using plt.annotate.
however, can see in picture, word 'something' in left bottom gets cropped. know how can fix this?
here code
#!/usr/bin/python import matplotlib matplotlib.use('agg') import matplotlib.pyplot plt import matplotlib.cm cm import operator o import numpy np n_groups = 5 means_men = (20, 35, 30, 35, 27) std_men = (2, 3, 4, 1, 2) means_women = (25, 32, 34, 20, 25) std_women = (3, 5, 2, 3, 3) fig, ax = plt.subplots() index = np.arange(n_groups) bar_width = 0.35 opacity = 0.4 error_config = {'ecolor': '0.3'} rects1 = plt.bar(index, means_men, bar_width, alpha=opacity, color='b', yerr=std_men, error_kw=error_config, label='men') rects2 = plt.bar(index + bar_width, means_women, bar_width, alpha=opacity, color='r', yerr=std_women, error_kw=error_config, label='women') #plt.xlabel('group') plt.ylabel('scores') plt.title('scores group , gender') plt.annotate('something', (0,0), (50,-40), xycoords = 'axes fraction', textcoords='offset points', va='top'); plt.annotate('something', (0,0), (200,-20), xycoords = 'axes fraction', textcoords='offset points', va='top'); plt.xticks(index + bar_width, ('a', 'b', 'c', 'd', 'e')) plt.legend() plt.savefig('barchart_3.png')
for reason, matplotlib clips aggressively. if add bbox_inches='tight'
save fig should include figure correctly,
plt.savefig('barchart_3.png', bbox_inches='tight')
more generally, can adjust main figure like,
plt.subplots_adjust(bottom=0.1)
Comments
Post a Comment