diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 6db9f897315e..ab7ffe4ee7b1 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1230,6 +1230,7 @@ def tk_window_focus(): 'matplotlib.tests.test_spines', 'matplotlib.tests.test_streamplot', 'matplotlib.tests.test_subplots', + 'matplotlib.tests.test_table', 'matplotlib.tests.test_text', 'matplotlib.tests.test_ticker', 'matplotlib.tests.test_tightlayout', diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 7d3a6813dee2..226ce5993d21 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -177,7 +177,7 @@ class Table(Artist): FONTSIZE = 10 AXESPAD = 0.02 # the border between the axes and table edge - def __init__(self, ax, loc=None, bbox=None): + def __init__(self, ax, loc=None, bbox=None, **kwargs): Artist.__init__(self) @@ -201,6 +201,7 @@ def __init__(self, ax, loc=None, bbox=None): self._autoRows = [] self._autoColumns = [] self._autoFontsize = True + self.update(kwargs) self.set_clip_on(False) @@ -453,7 +454,8 @@ def table(ax, cellLoc='right', colWidths=None, rowLabels=None, rowColours=None, rowLoc='left', colLabels=None, colColours=None, colLoc='center', - loc='bottom', bbox=None): + loc='bottom', bbox=None, + **kwargs): """ TABLE(cellText=None, cellColours=None, cellLoc='right', colWidths=None, @@ -517,7 +519,7 @@ def table(ax, cellColours = ['w' * cols] * rows # Now create the table - table = Table(ax, loc, bbox) + table = Table(ax, loc, bbox, **kwargs) height = table._approx_text_height() # Add the cells diff --git a/lib/matplotlib/tests/baseline_images/test_table/table_zorder.png b/lib/matplotlib/tests/baseline_images/test_table/table_zorder.png new file mode 100644 index 000000000000..21d4537c18fc Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_table/table_zorder.png differ diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py new file mode 100644 index 000000000000..6c173e8087ef --- /dev/null +++ b/lib/matplotlib/tests/test_table.py @@ -0,0 +1,39 @@ +import matplotlib.pyplot as plt +import numpy as np +from matplotlib.testing.decorators import image_comparison + + +@image_comparison(baseline_images=['table_zorder'], + extensions=['png'], + remove_text=True) +def test_zorder(): + data = [[ 66386, 174296,], + [ 58230, 381139,]] + + colLabels = ('Freeze', 'Wind') + rowLabels = ['%d year' % x for x in (100, 50)] + + + cellText = [] + yoff = np.array([0.0] * len(colLabels)) + for row in reversed(data): + yoff += row + cellText.append(['%1.1f' % (x/1000.0) for x in yoff]) + + t = np.linspace(0, 2*np.pi, 100) + plt.plot(t, np.cos(t), lw=4, zorder=2) + + plt.table(cellText=cellText, + rowLabels=rowLabels, + colLabels=colLabels, + loc='center', + zorder=-2, + ) + + plt.table(cellText=cellText, + rowLabels=rowLabels, + colLabels=colLabels, + loc='upper center', + zorder=4, + ) + plt.yticks([])