Skip to content

Delete vertical lines (or vertical rules) in plt.table? How to remove cell boundaries and shows table as scientific tables? #4044

Closed

Description

@arnaldorusso

Is there any way to remove the vertical lines in a matplotlib table?
Or even using text.usetex=True obtain a plot (using Arial for all texts and numbers) and append a table without vertical lines?

My code is this:

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style("ticks")
plt.rcParams.update({'xtick.labelsize' : 9,
                    'ytick.labelsize' : 9,
                    'mathtext.fontset' : 'stixsans',
                    'mathtext.default': 'regular'
                    })

plt.subplots_adjust(left=0.17, right=0.96, top=0.97, bottom=0.09)

fig = plt.figure(figsize=(5.5, 3.4))
ax = fig.add_subplot(111)

ax.plot([1, 2, 3, 4, 5, 6])
ax.set_xlabel('X Label')
ax.set_ylabel('Unit ('+u'μ'+r'velocity $\cdot$ m$^{-2}$ s$^{-1}$)',
             size=10)

l1 = ["","t0", "t1", "t2", "t3 ", "t4", "t5", "t6"]
l2 = ["DLI", 35, 38, 10, 22, 25, 85, 22]
t = ax.table(
            colWidths=[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
            cellText = [l1, l2],
            loc="upper center",
            colLoc="center",
            rowLoc="center",
            )
plt.savefig('mpl_table.png')
plt.show()

I tried to include some LaTeX stuff in another plot, which preserves Arial font, but does not render the table with horizontal lines Table correct. When I get the table as I want, the fonts can not be setted to Arial.

Here the codes show the plots in two steps. First generating the first plot and after running in a new session the second plot.

My main problem is to maintain the Arial font (mandatory rules in the guide for authors) and tables should be without vertical rules, as stated on first plot.

I have here three approachs and no one satisfy those recquirements (e.g. Arial font and table with no vertical lines)

I could not figure it out. Any clues?

Cheers,
Arnaldo.

Activity

  1. added this to the milestone on Jan 28, 2015
  2. tacaswell commented on Jan 28, 2015

    @tacaswell
    Member

    It does not look like this is something that is currently supported via matplotlib.table, but I suspect it would not be too hard to do by sub-classing matplotlib.table.Cell (to override draw to not use a rectangle so you can drop the vertical bars) and matplotlib.table.Table (to override add_cell to use your new sub-class of Cell, or extent Table to make tuning the Cell class possible).

    You might be better off in the short run annotate + axhline

  3. arnaldorusso commented on Jan 30, 2015

    @arnaldorusso
    Author

    Thank you @tacaswell for inlcuding this as wishlist label.
    Always addressing good ideas (annotate + axhline)!
    Cheers,

  4. tacaswell commented on Jan 30, 2015

    @tacaswell
    Member

    @arnaldorusso Sorry to not be of more help.

    When you get this figured out, can you consider providing it back as an example or an enhancement?

  5. arnaldorusso commented on Jan 30, 2015

    @arnaldorusso
    Author

    A development task:
    what could be the correct way, trying to do that @tacaswell ?
    include a type of cells to be drawn? inside

    class Table(Artist):
        def __init__(self, ax, loc=None, bbox=None, **kwargs):
    

    and include a parameter type as:

    def __init__(self, ax, loc=None, type=None, bbox=None, **kwargs)
    

    where self.types would be what??
    which is the best way to include a parameter on Table class to do not use rectagles of Cell class?!

    Sorry about my bad english 😁

  6. tacaswell commented on Jan 30, 2015

    @tacaswell
    Member

    I think that is along the lines of what I was thinking, but I would strongly advise against using the name 'type' and that shadows type which can have surprising behavior.

    I would go with something like:

    class Table(Artist):
        def __init__(self, ax, loc=None, bbox=None, cell_cls=None, cell_kwargs=None **kwargs):
            if cell_cls is None:
                cell_cls = Cell
            if cell_kwargs is None:
                cell_kwargs = dict()
    
           ....
           foo = cell_cls(..., **cell_kwargs)
           ....
    
    

    Where I have thrown ... in to mean 'what ever code makes sense'.

  7. arnaldorusso commented on Jan 30, 2015

    @arnaldorusso
    Author

    For sure type is not a good word... I'll try to do this as far as I can.
    Thanks for initial comments.
    =]

  8. added a commit that references this issue on Mar 22, 2015
  9. arnaldorusso commented on Apr 19, 2015

    @arnaldorusso
    Author

    Awesome!!

    Sorry to not dedicate my time on this issue!

    Thanks at all!

  10. markroxor commented on Jun 27, 2016

    @markroxor

    I tried using this implementation but it looks like since you're using "path". You won't get a closed figure which you could've got by "Rectangle" and therefore you cannot fill color in that cell. Is there a workaround for losing the vertical lines and at the same time keeping the cell color?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions