def table(ax,<EOL>cellText=None, cellColours=None,<EOL>cellLoc='<STR_LIT:right>', colWidths=None,<EOL>rowLabels=None, rowColours=None, rowLoc='<STR_LIT:left>',<EOL>colLabels=None, colColours=None, colLoc='<STR_LIT>',<EOL>loc='<STR_LIT>', bbox=None):
<EOL>if cellText is None:<EOL><INDENT>rows = len(cellColours)<EOL>cols = len(cellColours[<NUM_LIT:0>])<EOL>cellText = [['<STR_LIT>'] * rows] * cols<EOL><DEDENT>rows = len(cellText)<EOL>cols = len(cellText[<NUM_LIT:0>])<EOL>for row in cellText:<EOL><INDENT>assert len(row) == cols<EOL><DEDENT>if cellColours is not None:<EOL><INDENT>assert len(cellColours) == rows<EOL>for row in cellColours:<EOL><INDENT>assert len(row) == cols<EOL><DEDENT><DEDENT>else:<EOL><INDENT>cellColours = ['<STR_LIT:w>' * cols] * rows<EOL><DEDENT>if colWidths is None:<EOL><INDENT>colWidths = [<NUM_LIT:1.0>/cols] * cols<EOL><DEDENT>rowLabelWidth = <NUM_LIT:0><EOL>if rowLabels is None:<EOL><INDENT>if rowColours is not None:<EOL><INDENT>rowLabels = ['<STR_LIT>'] * cols<EOL>rowLabelWidth = colWidths[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>elif rowColours is None:<EOL><INDENT>rowColours = '<STR_LIT:w>' * rows<EOL><DEDENT>if rowLabels is not None:<EOL><INDENT>assert len(rowLabels) == rows<EOL><DEDENT>offset = <NUM_LIT:0><EOL>if colLabels is None:<EOL><INDENT>if colColours is not None:<EOL><INDENT>colLabels = ['<STR_LIT>'] * rows<EOL>offset = <NUM_LIT:1><EOL><DEDENT><DEDENT>elif colColours is None:<EOL><INDENT>colColours = '<STR_LIT:w>' * cols<EOL>offset = <NUM_LIT:1><EOL><DEDENT>if rowLabels is not None:<EOL><INDENT>assert len(rowLabels) == rows<EOL><DEDENT>if cellColours is None:<EOL><INDENT>cellColours = ['<STR_LIT:w>' * cols] * rows<EOL><DEDENT>table = Table(ax, loc, bbox)<EOL>height = table._approx_text_height()<EOL>for row in xrange(rows):<EOL><INDENT>for col in xrange(cols):<EOL><INDENT>table.add_cell(row+offset, col,<EOL>width=colWidths[col], height=height,<EOL>text=cellText[row][col],<EOL>facecolor=cellColours[row][col],<EOL>loc=cellLoc)<EOL><DEDENT><DEDENT>if colLabels is not None:<EOL><INDENT>for col in xrange(cols):<EOL><INDENT>table.add_cell(<NUM_LIT:0>, col,<EOL>width=colWidths[col], height=height,<EOL>text=colLabels[col], facecolor=colColours[col],<EOL>loc=colLoc)<EOL><DEDENT><DEDENT>if rowLabels is not None:<EOL><INDENT>for row in xrange(rows):<EOL><INDENT>table.add_cell(row+offset, -<NUM_LIT:1>,<EOL>width=rowLabelWidth or <NUM_LIT>, height=height,<EOL>text=rowLabels[row], facecolor=rowColours[row],<EOL>loc=rowLoc)<EOL><DEDENT>if rowLabelWidth == <NUM_LIT:0>:<EOL><INDENT>table.auto_set_column_width(-<NUM_LIT:1>)<EOL><DEDENT><DEDENT>ax.add_table(table)<EOL>return table<EOL>
TABLE(cellText=None, cellColours=None,
      cellLoc='right', colWidths=None,
      rowLabels=None, rowColours=None, rowLoc='left',
      colLabels=None, colColours=None, colLoc='center',
      loc='bottom', bbox=None)

Factory function to generate a Table instance.

Thanks to John Gill for providing the class and table.