-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Define the supported rcParams as code #30871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Until now, the parameter definition was dispersed: valid names and defaults are loaded from the canonical `matplotlibrc` data file. Docs are only available as comments in there. Validators are attached ad-hoc in `rcsetup.py`. This makes for a more formal definition of parameters, including meta-information, like validators, docs in a single place. It will simplify the rcParams related code in `matplotlib.__init__.py` and `matplotlib.rcsetup.py`. It also enables us to generate sphinx documentation on the parameters.
24ab51d to
fe72493
Compare
This definitely looks better than what's currently there. I think subheadings based on the artist/object that the rcParam applies to - like #lines, which will also make the right hand side really nice for quick skims I think. I think the two ways to achieve that are probably either manually add a family or peel off the family with a .split? |
|
Alternative: It would likely be feasible to define the rcParams via a TOML file, which we would carry around and read at startup like we do with matplotlibrc. Compare: Param("timezone", "UTC", validate_string,
description="a pytz timezone string, e.g., US/Central or Europe/Paris"),
Param("pcolor.shading", "auto", ["auto", "flat", "nearest", "gouraud"]),
Param("figure.constrained_layout.hspace", 0.02, validate_float,
description="Spacing between subplots, relative to the subplot sizes. Much "
"smaller than for tight_layout (figure.subplot.hspace, "
"figure.subplot.wspace) as constrained_layout already takes "
"surrounding texts (titles, labels, # ticklabels) into account."),and: [timezone]
default = "UTC"
validator = "validate_string"
description ="a pytz timezone string, e.g., US/Central or Europe/Paris"
[pcolor.shading]
default = "auto"
validator = '["auto", "flat", "nearest", "gouraud"]'
[figure.constrained_layout.hspace]
default = 0.02
validator = "validate_float"
description = """
Spacing between subplots, relative to the subplot sizes. Much
smaller than for tight_layout (figure.subplot.hspace, "
figure.subplot.wspace) as constrained_layout already takes
surrounding texts (titles, labels, # ticklabels) into account.
"""Which one is easier to maintain? There'll be slight complications that we need to be able to express None as a default value and that we have to define validators as strings and map them to code objects at runtime, but nothing that cannot be done. |
The toml file looks way easier to read/find the right value. And I like that the leveling structure means we can do group level stuff trivially (if I'm reading the TOML docs correctly), eg: [figure.constrained_layout]
description = "default settings for constrained layout, see <link to constrained layout docs>" |
|
I think it has been suggested for years that the matplotlibrc be a Python file instead of some parsable text format? |
|
@jklymak Tim is proposing a replacement for how rcParams are specified in rcsetup.py. Roughly this replaces the Separately it might be nice for users to be able to specify params using a TOML structure, but generally they're only going to need to specify the values so the structure here is a bit overkill for that. |
|
Sure I understand that - however, I don't see why we would add a new TOML format to the mix. |
|
Chiming in here with a note about a tool I used once in a work project for
schema validation: https://docs.python-cerberus.org/
…On Wed, Dec 17, 2025 at 12:49 PM Jody Klymak ***@***.***> wrote:
*jklymak* left a comment (matplotlib/matplotlib#30871)
<#30871 (comment)>
Sure I understand that - however, I don't see why we would add a new TOML
format to the mix.
—
Reply to this email directly, view it on GitHub
<#30871 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6EWOR3XN26URERDS2D4CGJTXAVCNFSM6AAAAACPHVZX2CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMNRWGQ4TCOBZGI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Thanks for the hint. Though I think schema validation is not our primary concern for now. We have potentially two schemas:
|
Because it's a ready made solution to the problem of defining specs for nested configurations, which is more or less what rcParams are. The alternative proposal of wrapping everything in |
It's a variant how to systematically represent that information. We are completely free to decide which one we like better. What I like about the TOML approach:
What I don't like about the TOML approach:
|
I think it'd be nice to pull the configuration out of rcsetup even if we don't go the TOML route. |
I did not do this for a start, because one then needs to import all the validators, and that gets messy. But rearrangement is possible and will happen in some form. |
Current status
Until now, the parameter definition was dispersed: valid names and defaults are loaded from the canonical
matplotlibrcdata file. Docs are only available as comments in there. Validators are attached ad-hoc inrcsetup.py.Proposed change
Define the parameters in code, including meta-information, like validators, docs in a single place. It will simplify the rcParams related code in
matplotlib.__init__.pyandmatplotlib.rcsetup.py. It also enables us to generate sphinx documentation on the parameters.Closes #23531.
Superseeds #26088. Ensuring consistency through tests is a better approach than trying to be able to exactly reproduce matplotlibrc.
Discarded alternative: Use another stuctured data file to store the information. Among available formats, I would only find YAML easy enough to human-read and -write this kind of structured information. But I don't want to introduce a YAML parser as a dependency.
Notes:
some.paramcan directly line the parameters.How to review:
https://output.circle-artifacts.com/output/job/18c5a4fc-ca4b-4e81-b608-3b175644c660/artifacts/0/doc/build/html/users/explain/customizing.html#description-of-rcparams
Feedback welcome.