How to extend the space for y ticks in barh - python matplotlib
Question: Please see attached image

[![enter image description
here](http://i.stack.imgur.com/gL2A0.jpg)](http://i.stack.imgur.com/gL2A0.jpg)

I have the source code as follows in python

    
    
    def plotBarChartH(self,data):
               LogManager.logDebug('Executing Plotter.plotBarChartH')
    
               if type(data) is not dict:
                   LogManager.logError('Input data parameter is not in right format. Need a dict')
                   return False
    
               testNames = []
               testTimes = []
    
               for val in data:
                    testNames.append(val)
                    testTimes.append(data[val])
    
               matplotlib.rcParams.update({'font.size': 8})     
               yPos = np.arange(len(testNames))
               plt.barh(yPos, testTimes, height=0.4, align='center', alpha=0.4)
               plt.yticks(yPos, testNames)
               plt.xlabel('time (seconds)')
               plt.title('Test Execution Times')
               savePath = os.path.join(ConfigurationManager.applicationConfig['robotreportspath'],'bar.jpg')
               plt.savefig(savePath)
               plt.clf()
               return True
    

The bar looks fine but I have two issues

  1. How can the text in y-axis can be shown in full? I mean some text are cut-off and i want to extend the space in occupies so that it can be displayed in full.

  2. Can I Increase the whole plot area on which the charts are drawn? I want to increase the width of of plot area so that image looks bit bigger

thanks


Answer: You can set the figure size (in inches) explicitly when you create a `Figure`
object with `plt.figure(figsize=(width,height)), and call`plt.tight_layout()`
to make room for your tick labels as follows:

    
    
    import matplotlib.pyplot as plt
    
    names = ['Content Channels','Kittens for Xbox Platform','Tigers for PS Platform',
             'Content Series', 'Wombats for Mobile Platform']
    
    values = [260, 255, 420, 300, 270]
    
    fig = plt.figure(figsize=(10,4))
    ax = fig.add_subplot(111)
    yvals = range(len(names))
    ax.barh(yvals, values, align='center', alpha=0.4)
    plt.yticks(yvals,names)
    plt.tight_layout()
    
    plt.show()
    

[![enter image description
here](http://i.stack.imgur.com/PYiI8.png)](http://i.stack.imgur.com/PYiI8.png)

