Skip to content

Commit

Permalink
Backport PR matplotlib#29258: Adding font Size as default parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
saikarna913 authored and meeseeksmachine committed Dec 16, 2024
1 parent efefcf4 commit 0e995ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/matplotlib/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,9 @@ def table(ax,
if rowLabelWidth == 0:
table.auto_set_column_width(-1)

# set_fontsize is only effective after cells are added
if "fontsize" in kwargs:
table.set_fontsize(kwargs["fontsize"])

ax.add_table(table)
return table
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,15 @@ def test_table_dataframe(pd):
for r, (index, row) in enumerate(df.iterrows()):
for c, col in enumerate(df.columns if r == 0 else row.values):
assert table[r if r == 0 else r+1, c].get_text().get_text() == str(col)


def test_table_fontsize():
# Test that the passed fontsize propagates to cells
tableData = [['a', 1], ['b', 2]]
fig, ax = plt.subplots()
test_fontsize = 20
t = ax.table(cellText=tableData, loc='top', fontsize=test_fontsize)
cell_fontsize = t[(0, 0)].get_fontsize()
assert cell_fontsize == test_fontsize, f"Actual:{test_fontsize},got:{cell_fontsize}"
cell_fontsize = t[(1, 1)].get_fontsize()
assert cell_fontsize == test_fontsize, f"Actual:{test_fontsize},got:{cell_fontsize}"

0 comments on commit 0e995ce

Please sign in to comment.