-
-
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
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
|
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 |
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:
|
| Matplotlib's configuration parameters (rcParams) control the behavior and | ||
| appearance of plots. These parameters are stored in a dict-like variable | ||
| called :data:`matplotlib.rcParams` (also accessible via ``plt.rcParams``). | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be worth linking back to the styling doc for folks who accidentally landed on this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pure reference page. I don't feel a stong need to link to usage descriptions. - In particular also because styling is only a partial aspect of rcParams. - But you are welcome to propose a sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"For guidance on using RC parameters to control styling, see :ref:`customization" but I also see your point, especially with the current state of these docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"For guidance on using RC parameters to control styling, see :ref:`customization" but I also see your point, especially with the current state of these docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this in a follow-up. The following places need cross-referencing and sorting of responsibilities:
599ad24 to
61563f5
Compare
|
Coverage failure is annoyingly real |
Yes it is real. The rst-doc generating code is not run in the tests. But I'd say this is not annoying. It is not affecting runtime-relevant code, so while the coverage percentage formally goes down, the test coverage of behavior is not changed. |
I think it's annoying in an I'd like this coverage decrease to not persist way. I'm fine w/ the function being excluded using |
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.
61563f5 to
28841c8
Compare
|
Ok. I've added |
Follow up to https://github .com/matplotlib/pull/30871#discussion_r2674234162.
Follow up to https://github .com/matplotlib/pull/30871#discussion_r2674234162.
Follow up to https://github .com/matplotlib/pull/30871#discussion_r2674234162.
Follow up to https://github .com/matplotlib/pull/30871#discussion_r2674234162.
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.