Skip to content

Minor Bug on table.py #5350

@jcolonese

Description

@jcolonese

Hello,

I'm a regular user of matplotlib in windows but not so into hard programming. When trying to draw a colored table with uneven shape (1 row and 10 columns) and just filled colors in each cell, I've found some minor problems. I was using pyplot.table without setting cellText. I've noticed that the error messages on master are quite more clear than the one in my version, but this particular issue is still on there.
When someone does not explicit set cellText contents, the function gets the table shape by cellColours, but positions of rows and cols variables are changed in line 563 (from master). It should be just like in line 580, I think.

Hope that helped!

Cheers

Juan

def table(ax,
          cellText=None, cellColours=None,
          cellLoc='right', colWidths=None,
          rowLabels=None, rowColours=None, rowLoc='left',
          colLabels=None, colColours=None, colLoc='center',
          loc='bottom', bbox=None, edges='closed',
          **kwargs):
    """
    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, edges='closed')
    Factory function to generate a Table instance.
    Thanks to John Gill for providing the class and table.
    """

    # Check we have some cellText
    if cellText is None:
        # assume just colours are needed
        rows = len(cellColours)
        cols = len(cellColours[0])
       cellText = [[''] * rows] * cols  #jcolonese: I think it should be 
                                                   #" cellText = [[''] * cols] * rows "

    rows = len(cellText)
    cols = len(cellText[0])
    for row in cellText:
        if len(row) != cols:
            msg = "Each row in 'cellText' must have {0} columns"
            raise ValueError(msg.format(cols))

    if cellColours is not None:
        if len(cellColours) != rows:
            raise ValueError("'cellColours' must have {0} rows".format(rows))
        for row in cellColours:
            if len(row) != cols:
                msg = "Each row in 'cellColours' must have {0} columns"
                raise ValueError(msg.format(cols))
    else:
        cellColours = ['w' * cols] * rows #jcolonese: exactly like here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions