python + matplotlib: barh plot show incomplete YTick labels - how to dynamically move the plot area to the right to fit the given YTickLabels? -


i'm using matplotlib plot barh plot file. unfortunate, yticklaels bit long , plot area won't move right automatically. there way move plot area right automatically won't have problems incomplete yticklabels?

the code use following:

import matplotlib mpl mpl.use('agg') import matplotlib.pyplot plt d = {u'label1':26, u'label2 longer others': 17, u'label3 not short either':30} fig = plt.figure(figsize=(5.5,3),dpi=300) ax = fig.add_subplot(111) ax.grid(true,which='both') bar = ax.barh(range(1,len(d)+1,1),d.values(),0.4,align='center') plt.yticks(range(1,len(d)+1,1), d.keys(), size='small') fig.savefig('d_bar.png') 

here output: output of barh

how can fix this? thanks

actually, there automatic way of doing now: tight_layout.

in case:

import matplotlib mpl mpl.use('agg') import matplotlib.pyplot plt d = {u'label1':26, u'label2 longer others': 17,       u'label3 not short either':30} fig = plt.figure(figsize=(5.5,3),dpi=300) ax = fig.add_subplot(111) ax.grid(true,which='both') bar = ax.barh(range(1,len(d)+1,1),d.values(),0.4,align='center') plt.yticks(range(1,len(d)+1,1), d.keys(), size='small') fig.tight_layout() fig.savefig('d_bar.png') 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -