Skip to content

Commit b44d047

Browse files
authored
Merge pull request matplotlib#29324 from meeseeksmachine/auto-backport-of-pr-29258-on-v3.10.x
Backport PR matplotlib#29258 on branch v3.10.x (Adding font Size as default parameter)
2 parents 8f6578e + 0e995ce commit b44d047

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Diff for: lib/matplotlib/table.py

+4
Original file line numberDiff line numberDiff line change
@@ -838,5 +838,9 @@ def table(ax,
838838
if rowLabelWidth == 0:
839839
table.auto_set_column_width(-1)
840840

841+
# set_fontsize is only effective after cells are added
842+
if "fontsize" in kwargs:
843+
table.set_fontsize(kwargs["fontsize"])
844+
841845
ax.add_table(table)
842846
return table

Diff for: lib/matplotlib/tests/test_table.py

+12
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,15 @@ def test_table_dataframe(pd):
270270
for r, (index, row) in enumerate(df.iterrows()):
271271
for c, col in enumerate(df.columns if r == 0 else row.values):
272272
assert table[r if r == 0 else r+1, c].get_text().get_text() == str(col)
273+
274+
275+
def test_table_fontsize():
276+
# Test that the passed fontsize propagates to cells
277+
tableData = [['a', 1], ['b', 2]]
278+
fig, ax = plt.subplots()
279+
test_fontsize = 20
280+
t = ax.table(cellText=tableData, loc='top', fontsize=test_fontsize)
281+
cell_fontsize = t[(0, 0)].get_fontsize()
282+
assert cell_fontsize == test_fontsize, f"Actual:{test_fontsize},got:{cell_fontsize}"
283+
cell_fontsize = t[(1, 1)].get_fontsize()
284+
assert cell_fontsize == test_fontsize, f"Actual:{test_fontsize},got:{cell_fontsize}"

0 commit comments

Comments
 (0)