-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
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. |
ea06190 to
0ccad61
Compare
|
I've reformatted the parameter definition to one value per line, which makes this a bit more readable. For now, I'd say the code representation is good enough. We can always later consider whether TOML might yield additional advantages. |
0ccad61 to
fd80b8b
Compare
|
I've added links to so that individual :rc: entries link to their parameter description (not any more to the reproduced default matplotlibrc file. Overall, I'd say this is ready to go into 3.11 as it is already a massive improvement over the current state. At the same time, the risk is relatively low because the rcParams as code are currently only used for the docs. They are not used for code logic. The only think that is worth discussing is where to put the list of rcParams in the docs. Is there a better place than |
e207de8 to
9de7838
Compare
I think they should be on their own page, linked out to from customizing. ETA: mostly b/c they're a standalone reference independent from the customizing guide/tutorial, so it's a clear separation of purpose/scope. |
|
Yes, but where should the new page be? Is this also |
9de7838 to
35eb9ed
Compare
I think it's documenting the rcparams API and would be far better than current docs so I'd put a new reference page under the style module. |
The style module is not the right place. Styles are realized through rcParams, but rcParams are a more fundamental concept. Conceptually, it belongs in https://matplotlib.org/devdocs/api/rcsetup_api.html, but that whole module is basically not user-facing. The main user-facing functions are all in the top-level matplotlib module, but listing the parameters there is also not in proportion. I see the following options:
The point is that our current docs structure cannot reasonbly accomodate this information. But I don't want to rearchitect the docs structure right now. OTOH I think this is already a valuable improvment, no matter where it lives. |
35eb9ed to
2475502
Compare
On the one hand I'm thinking do this, on the other I'm thinking that it can get it's own page under rc if/when configuration gets pulled out of rcsetup. |
|
The advantage of a new page is that we can delete it later and redirect it to another location. That's more difficult with rcsetup. |
I was thinking more of avoiding the redirect if down the line it gets its own page in API b/c it gets its own file c/o #30871 (comment), but redirects are cheap enough that I'm also pro new page now in case the rearch doesn't happen |
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.
2475502 to
9dca73a
Compare
|
This is now ready as a complete minimal update. See parameter list: https://output.circle-artifacts.com/output/job/76615068-68c0-4ccd-9a2b-a7f52a8ecf0c/artifacts/0/doc/build/html/users/explain/configuration.html As already said above: Overall, I'd say this is ready to go into 3.11 as it is already a massive improvement over the current state. At the same time, the risk is relatively low because the rcParams as code are currently only used for the docs. They are not used for code logic - any changes to that would be 3.12+ Review tips:
|
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.