Skip to content

Adding font Size as default parameter#29258

Merged
oscargus merged 34 commits into
matplotlib:mainfrom
saikarna913:main
Dec 16, 2024
Merged

Adding font Size as default parameter#29258
oscargus merged 34 commits into
matplotlib:mainfrom
saikarna913:main

Conversation

@saikarna913
Copy link
Copy Markdown
Contributor

Adding the font size as default parameter
This PR Solves #29202

PR summary

-This PR automatically adjusts the font size when creating the table, provided the fontsize argument is specified, without requiring an explicit call to the set_fontsize function.
-Automatically applying the font size ensures consistent styling during table creation, streamlining the process for users. It eliminates the need for additional method calls

PR checklist

import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
x = np.linspace(0, 10, 100)
y = x + 1
tableData = [['a', 1], ['b', 1]]

# Create the figure and axis objects
fig, ax = plt.subplots()

# Plot the data
ax.plot(x, y)

# Add a table
t = ax.table(
    cellText=tableData,  # Table content
    loc='top',  # Position of the table
    cellLoc='center',  # Center-align the text in cells
    fontsize=30  # Set the font size for the table
)

# Save the figure as an image
plt.savefig('output_plot_with_table_after.png')  # Save as PNG file

# Optionally, close the plot (no need to display it)
plt.close()

I got this output
image

@saikarna913
Copy link
Copy Markdown
Contributor Author

saikarna913 commented Dec 8, 2024

@tacaswell please help me why mypy is failing I haven't changed the pylab.py code. please approve and merge this pr is there is no issue

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Dec 8, 2024

The mypy issue is unrelated and happens also on other PRs. It can be ignored here.

@saikarna913
Copy link
Copy Markdown
Contributor Author

saikarna913 commented Dec 9, 2024

@rcomer can you review my PR and approve it, As per @timhoffm suggestion, I guess mypy issue can be ignored.

@saikarna913
Copy link
Copy Markdown
Contributor Author

@timhoffm i guess now this PR can be merged. it would be a great encouragement for me as a beginner in open source. if there is any issue please let me know

@saikarna913
Copy link
Copy Markdown
Contributor Author

@timhoffm I don't understand why these are passing sometimes and failing. in the last commit pre-commit. ci failed due to the whitespace, so I removed the whitespace and then [Tests / Python 3.13 on macos-14 (pull_request)] is failing

@rcomer
Copy link
Copy Markdown
Member

rcomer commented Dec 10, 2024

Unfortunately the MacOS tests can be flakey and sometimes show failures that are not caused by the PR. You just got unlucky when you removed the white space.

Comment thread lib/matplotlib/table.py Outdated
Comment thread lib/matplotlib/table.pyi Outdated
Comment thread lib/matplotlib/tests/test_table.py Outdated
Comment thread lib/matplotlib/tests/test_table.py Outdated
@rcomer
Copy link
Copy Markdown
Member

rcomer commented Dec 16, 2024

I wasn’t sure if a docstring change would be needed since fontsize is already listed as a Table property under kwargs.

@timhoffm
Copy link
Copy Markdown
Member

I wasn’t sure if a docstring change would be needed since fontsize is already listed as a Table property under kwargs.

The important thing is that every parameter is documented, direct or indirectly. There is no 1:1 relation that an explicit parameter must be documented explicitly, or vice versa. Typically, if we use explicit parameters for Artist properties, it's because they have a special meaning / modified functionality, which warrant explicit documentation. But here we just need the value to make the table behave as expected. We don't need to communicate additional information and thus don't need an explicit docstring.

Copy link
Copy Markdown
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take one of my two comments: Either make the new fontsize parameter keyword-only or don't introduce an explicit fontsize parameter and instead take the value from kwargs.

Comment thread lib/matplotlib/table.py Outdated
Comment thread lib/matplotlib/table.py Outdated
saikarna913 and others added 4 commits December 16, 2024 15:42
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@oscargus oscargus merged commit 45e0cf3 into matplotlib:main Dec 16, 2024
@oscargus
Copy link
Copy Markdown
Member

Thanks! One may consider if this is a bugfix and therefore should be backported.

@timhoffm
Copy link
Copy Markdown
Member

@meeseeksdev backport to v3.10.1

@lumberbot-app
Copy link
Copy Markdown

lumberbot-app Bot commented Dec 16, 2024

Something went wrong ... Please have a look at my logs.

It seems that the branch you are trying to backport to does not exist.

@timhoffm
Copy link
Copy Markdown
Member

@meeseeksdev backport to v3.10.x

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Dec 16, 2024
@rcomer rcomer modified the milestones: v3.11.0, v3.10.1 Dec 16, 2024
timhoffm added a commit that referenced this pull request Dec 16, 2024
…258-on-v3.10.x

Backport PR #29258 on branch v3.10.x (Adding font Size as default parameter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bugfix Pull requests that fix identified bugs topic: table

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: fontsize in tables not working

4 participants