FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Backport PR #25052 on branch v3.7.x (Support both Bbox and list for bbox to table/Table) by meeseeksmachine · Pull Request #25182 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 6 additions & 3 deletions lib/matplotlib/table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
loc : str
The position of the cell with respect to *ax*. This must be one of
the `~.Table.codes`.
bbox : `.Bbox` or None
bbox : `.Bbox` or [xmin, ymin, width, height], optional
A bounding box to draw the table into. If this is not *None*, this
overrides *loc*.

Expand Down Expand Up @@ -595,7 +595,10 @@ def _update_positions(self, renderer):

if self._bbox is not None:
# Position according to bbox
rl, rb, rw, rh = self._bbox
if isinstance(self._bbox, Bbox):
rl, rb, rw, rh = self._bbox.bounds
else:
rl, rb, rw, rh = self._bbox
self.scale(rw / w, rh / h)
ox = rl - l
oy = rb - b
Expand Down Expand Up @@ -710,7 +713,7 @@ def table(ax,
The position of the cell with respect to *ax*. This must be one of
the `~.Table.codes`.

bbox : `.Bbox`, optional
bbox : `.Bbox` or [xmin, ymin, width, height], optional
A bounding box to draw the table into. If this is not *None*, this
overrides *loc*.

Expand Down
30 changes: 29 additions & 1 deletion lib/matplotlib/tests/test_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.testing.decorators import image_comparison
from matplotlib.testing.decorators import image_comparison, check_figures_equal

from matplotlib.table import CustomCell, Table
from matplotlib.path import Path
from matplotlib.transforms import Bbox


def test_non_square():
Expand Down Expand Up @@ -194,3 +195,30 @@ def test_table_cells():
# properties and setp
table.properties()
plt.setp(table)


@check_figures_equal(extensions=["png"])
def test_table_bbox(fig_test, fig_ref):
data = [[2, 3],
[4, 5]]

col_labels = ('Foo', 'Bar')
row_labels = ('Ada', 'Bob')

cell_text = [[f"{x}" for x in row] for row in data]

ax_list = fig_test.subplots()
ax_list.table(cellText=cell_text,
rowLabels=row_labels,
colLabels=col_labels,
loc='center',
bbox=[0.1, 0.2, 0.8, 0.6]
)

ax_bbox = fig_ref.subplots()
ax_bbox.table(cellText=cell_text,
rowLabels=row_labels,
colLabels=col_labels,
loc='center',
bbox=Bbox.from_extents(0.1, 0.2, 0.9, 0.8)
)

Back | FazBrowse Home | New Git URL