Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Added ScientificTable type and option.
Browse files Browse the repository at this point in the history
This creates a table with no vertical lines for issue matplotlib#4044.
  • Loading branch information
David authored and dkua committed Apr 1, 2015
1 parent 28bed34 commit b30c789
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/matplotlib/table.py
Expand Up @@ -34,6 +34,7 @@
from matplotlib import docstring
from .text import Text
from .transforms import Bbox
from matplotlib.path import Path


class Cell(Rectangle):
Expand Down Expand Up @@ -145,6 +146,16 @@ def set_text_props(self, **kwargs):
'update the text properties with kwargs'
self._text.update(kwargs)

class ScientificCell(Cell):

def get_path(self):
path = Path([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0],
[0.0, 0.0]],
[Path.MOVETO, Path.LINETO, Path.MOVETO, Path.LINETO,
Path.CLOSEPOLY],
readonly=True)
return path


class Table(Artist):
"""
Expand Down Expand Up @@ -454,12 +465,26 @@ def get_celld(self):
return self._cells


class ScientificTable(Table):

def add_cell(self, row, col, *args, **kwargs):
""" Add a scientific cell to the table. """
xy = (0, 0)

cell = ScientificCell(xy, *args, **kwargs)
cell.set_figure(self.figure)
cell.set_transform(self.get_transform())

cell.set_clip_on(False)
self._cells[(row, col)] = cell


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,
loc='bottom', bbox=None, tableType=None,
**kwargs):
"""
TABLE(cellText=None, cellColours=None,
Expand All @@ -472,6 +497,7 @@ def table(ax,
Thanks to John Gill for providing the class and table.
"""

# Check we have some cellText
if cellText is None:
# assume just colours are needed
Expand Down Expand Up @@ -527,7 +553,11 @@ def table(ax,
cellColours = ['w' * cols] * rows

# Now create the table
table = Table(ax, loc, bbox, **kwargs)
if tableType == "scientific":
table = ScientificTable(ax, loc, bbox, **kwargs)
else:
table = Table(ax, loc, bbox, **kwargs)

height = table._approx_text_height()

# Add the cells
Expand Down

0 comments on commit b30c789

Please sign in to comment.