title: Matplotlib: Table: Columns and rows of unequal length
body: <p>After digging inside the Table class and Text class, I managed to make a way to produce tables with unequal width and height, depending on the size of the text inside the cells (I borrowed the matplotlib example for this):</p>
  
  <pre><code>"""
  Demo of table function to display a table within a plot.
  """
  import numpy as np
  import matplotlib.pyplot as plt
  #from matplotlib.backends.backend_pdf import PdfPages
  
  data = [[  66386,  174296,   75131,  577908,   32015],
          [  58230,  381139,   78045,   99308,  160454],
          [  89135,   80552,  152558,  497981,  603535],
          [  78415,   81858,  150656,  193263,   69638],
          [ 139361,  331509,  343164,  781380,   52269]]
  columns = ('Freeze', 'Tornados', 'Flood', 'Quake', 'Hail')
  n_rows = len(data)
  y_offset = np.array([0.0] * len(columns))
  cell_text = []
  for row in range(n_rows):
      y_offset = y_offset + data[row]
      cell_text.append(['%1.1f' % (x/1000.0) for x in y_offset])
  cell_text = np.array(cell_text)
  cell_colors = np.tile(np.ones_like(cell_text,float)[...,None] -0.5
                        ,(1,1,3))
  fig = plt.figure()
  axes = fig.add_subplot(111)
  the_table = axes.table(cellText=cell_text,
                        colLabels=columns,
                          cellColours=cell_colors,
                        loc='center')
  #he_table.properties()['celld'][0,0].get_text().set_fontweight(1000)
  the_table.auto_set_font_size(False) 
  the_table.scale(3, 3) 
  the_table.set_fontsize(20)
  table_prop = the_table.properties()
  #fill the transpose or not, if we need col height or row width respectively.
  rows_heights = [[] for i in range(len([cells for cells in 
                                       table_prop['celld'] if cells[1]==0]))]
  cols_widths = [[] for i in range(len([cells for cells in 
                                       table_prop['celld'] if cells[0]==0]))]
  for cell in table_prop['celld']:
      text = table_prop['celld'][(0,0)]._text._text
  
      bounds = table_prop['celld'][cell].get_text_bounds(fig.canvas.get_renderer())
      cols_widths[cell[1]].append(bounds[2])
      rows_heights[cell[0]].append(bounds[3])
  
  cols_width = [max(widths) for widths in cols_widths]
  rows_height = [max(heights) for heights in rows_heights]
  for cell in table_prop['celld']:
      bounds = table_prop['celld'][cell].get_text_bounds(fig.canvas.get_renderer())                                            
      table_prop['celld'][cell].set_bounds(*(bounds[:2]+(1.*cols_width[cell[1]],
                                                         1.1*rows_height[cell[0]],
                                                       )))
  
  
  plt.axis('off')
  plt.show()
  </code></pre>
  
  <p>The result is the following:</p>
  
  <p><a href="https://i.stack.imgur.com/Prnzd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Prnzd.png" alt="enter image description here"></a></p>
  
  <p>While the cells with text render correctly the width and height of the respective columns, the cells with numbers fail to. An obvious way to fix it is to multiply the <code>cols_width</code> and <code>rows_height</code> with sth more than 1. Does anyone have an idea why this is happening and might provide a solution?</p>