Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit75e2d22

Browse files
authored
Merge pull request#25052 from oscargus/tablebbox
Support both Bbox and list for bbox to table/Table
2 parentsc9d7bff +51aba38 commit75e2d22

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

‎lib/matplotlib/table.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
285285
loc : str
286286
The position of the cell with respect to *ax*. This must be one of
287287
the `~.Table.codes`.
288-
bbox : `.Bbox` orNone
288+
bbox : `.Bbox` or[xmin, ymin, width, height], optional
289289
A bounding box to draw the table into. If this is not *None*, this
290290
overrides *loc*.
291291
@@ -595,7 +595,10 @@ def _update_positions(self, renderer):
595595

596596
ifself._bboxisnotNone:
597597
# Position according to bbox
598-
rl,rb,rw,rh=self._bbox
598+
ifisinstance(self._bbox,Bbox):
599+
rl,rb,rw,rh=self._bbox.bounds
600+
else:
601+
rl,rb,rw,rh=self._bbox
599602
self.scale(rw/w,rh/h)
600603
ox=rl-l
601604
oy=rb-b
@@ -710,7 +713,7 @@ def table(ax,
710713
The position of the cell with respect to *ax*. This must be one of
711714
the `~.Table.codes`.
712715
713-
bbox : `.Bbox`, optional
716+
bbox : `.Bbox` or [xmin, ymin, width, height], optional
714717
A bounding box to draw the table into. If this is not *None*, this
715718
overrides *loc*.
716719

‎lib/matplotlib/tests/test_table.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
importmatplotlib.pyplotasplt
22
importnumpyasnp
3-
frommatplotlib.testing.decoratorsimportimage_comparison
3+
frommatplotlib.testing.decoratorsimportimage_comparison,check_figures_equal
44

55
frommatplotlib.tableimportCustomCell,Table
66
frommatplotlib.pathimportPath
7+
frommatplotlib.transformsimportBbox
78

89

910
deftest_non_square():
@@ -194,3 +195,30 @@ def test_table_cells():
194195
# properties and setp
195196
table.properties()
196197
plt.setp(table)
198+
199+
200+
@check_figures_equal(extensions=["png"])
201+
deftest_table_bbox(fig_test,fig_ref):
202+
data= [[2,3],
203+
[4,5]]
204+
205+
col_labels= ('Foo','Bar')
206+
row_labels= ('Ada','Bob')
207+
208+
cell_text= [[f"{x}"forxinrow]forrowindata]
209+
210+
ax_list=fig_test.subplots()
211+
ax_list.table(cellText=cell_text,
212+
rowLabels=row_labels,
213+
colLabels=col_labels,
214+
loc='center',
215+
bbox=[0.1,0.2,0.8,0.6]
216+
)
217+
218+
ax_bbox=fig_ref.subplots()
219+
ax_bbox.table(cellText=cell_text,
220+
rowLabels=row_labels,
221+
colLabels=col_labels,
222+
loc='center',
223+
bbox=Bbox.from_extents(0.1,0.2,0.9,0.8)
224+
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp