Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
arnaldorusso opened this issue Jan 28, 2015 · 8 comments

Comments

@arnaldorusso
Copy link

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.

@tacaswell tacaswell added this to the unassigned milestone Jan 28, 2015
@tacaswell
Copy link
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

@arnaldorusso
Copy link
Author

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

@tacaswell
Copy link
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?

@arnaldorusso
Copy link
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 😁

@tacaswell
Copy link
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'.

@arnaldorusso
Copy link
Author

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

anthonycho added a commit to anthonycho/matplotlib that referenced this issue Mar 20, 2015
anthonycho added a commit to anthonycho/matplotlib that referenced this issue Mar 20, 2015
…es a class level dictionary and modified code to use it.
anthonycho added a commit to anthonycho/matplotlib that referenced this issue Mar 20, 2015
dkua pushed a commit to dkua/matplotlib that referenced this issue Mar 22, 2015
This creates a table with no vertical lines for issue matplotlib#4044.
dkua pushed a commit to dkua/matplotlib that referenced this issue Apr 1, 2015
This creates a table with no vertical lines for issue matplotlib#4044.
dkua pushed a commit to dkua/matplotlib that referenced this issue Apr 1, 2015
This creates a table with no vertical lines for issue matplotlib#4044.
@arnaldorusso
Copy link
Author

Awesome!!

Sorry to not dedicate my time on this issue!

Thanks at all!

@markroxor
Copy link

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
Projects
None yet
Development

No branches or pull requests

3 participants