Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@founta
Copy link
Contributor

@founta founta commented May 9, 2025

PR summary

Closes #30021. Previously, users were unable to set font.sans-serif by using keyword arguments to the rc function as described in the issue. This change adds the sans alias to sans-serif. It appears to function as intended:

>>> import matplotlib as mpl
>>> mpl.rcParams["font.sans-serif"]
['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
>>> mpl.rc("font", sans="Verdana")
>>> mpl.rcParams["font.sans-serif"]
['Verdana']

The change to the alias list in the docstring also appears to be OK:
image

No tests seemed to fail following this change.

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@tacaswell
Copy link
Member

Thank you for working on this!

Can you please add a test that it works as expected? A quick look at lib/matplotlib/tests/test_rcparam.py doesn't show existing tests of any of the aliases! I think a parameterized test would be the right path here to catch them all on in pass.


This is also a good example of where line coverage is miss-leading: all of the lines are covered but none of the functionality is actually tested!

@tacaswell tacaswell added this to the v3.11.0 milestone May 9, 2025
@founta
Copy link
Contributor Author

founta commented May 10, 2025

I have added tests for the rc aliases:

$ pytest lib/matplotlib/tests/test_rcparams.py -k test_rc_aliases
pytest-xvfb could not find Xvfb. You can install it to prevent windows from being shown.
===================================== test session starts ======================================
platform linux -- Python 3.11.12, pytest-8.3.5, pluggy-1.5.0
rootdir: /home/founta/matplotlib/matplotlib
configfile: pyproject.toml
plugins: cov-6.1.1, xdist-3.6.1, timeout-2.4.0, xvfb-3.1.1, rerunfailures-15.1
collected 236 items / 228 deselected / 8 selected                                              

lib/matplotlib/tests/test_rcparams.py ........                                           [100%]

============================== 8 passed, 228 deselected in 0.47s ===============================

@story645 story645 merged commit 24bcabb into matplotlib:main May 12, 2025
48 checks passed
@story645
Copy link
Member

Thanks for the pr @founta, hope to see you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Setting font.sans-serif is impossible by the intended way using matplotlib.rc because it contains a hyphen.

4 participants