-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support individual styling of major and minor grid through rcParams #29481
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
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.
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.
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.
Thanks for the PR. The solution is surprisingly simple. I would have thought that there are more complications because of the concurrent settings and the need for backward compatibility.
The only improvement needed is the clearer distinction on the color and linewidth parameter values between "none" and None
.
One related aspect to think about: Do we anticipate that we'll need a distinction between x and y axis as well? Because if so, we should directly introduce these. |
The `*_or_None` validators have accepted any capitalization of the string "none" as input. This is overly permissive and will likely lead to conflicts in the future because we cannot distinguish between resolving to `None` and `"none"` which may be need for some parameters in the future. Inspired by matplotlib#29481.
I made the suggested changes.
Can you clarify what you meant by "a distinction between x and y axis"? Do you mean something like rcParams["grid.major.xaxis.linestyle"] = ":"
rcParams["grid.major.yaxis.linestyle"] = "-" |
The `*_or_None` validators have accepted any capitalization of the string "none" as input. This is overly permissive and will likely lead to conflicts in the future because we cannot distinguish between resolving to `None` and `"none"` which may be need for some parameters in the future. Inspired by matplotlib#29481.
Sorry I forgot to update the ".pyi" file |
Basically yes. Exact spelling t.b.d. |
I think this is possible however it might look "ugly". The change will require the One possible way is by accessing the Another way is to add an extra required argument to the constructor of Any thoughts on those? |
We already rely on matplotlib/lib/matplotlib/axis.py Lines 106 to 116 in 3b329d9
It's ok to use that. Spelling: We have "xaxis", "xticks", "xscale" as axis-dependent names (but they are all also used in the python interface). We do not have any xgrid or similar names. Options:
None of them look like the obvious right choice to me. |
Out of the four, I prefer two:
I will try to implement the second one for now. I can change the key later. |
The `*_or_None` validators have accepted any capitalization of the string "none" as input. This is overly permissive and will likely lead to conflicts in the future because we cannot distinguish between resolving to `None` and `"none"` which may be need for some parameters in the future. Inspired by matplotlib#29481.
I implemented the x and y axis distinction however I came across something that needs further clarification. Right now "grid.xaxis.major.linestyle" is a valid key but "grid.xaxis.linestyle" is not. Should it be a valid option as well? If so it is unclear which of "grid.major.linestyle"and "grid.xaxis.linestyle" should take precedence. |
No, we don't need "grid.xaxis.linestyle". If starting from scratch, I'd just have the granular settings "grid.xaxis.major.linestyle" etc. After all, these are advanced style configuration options, and if somebody cares to adapt them, it's ok to write out the details. We keep the high-level ones "grid.linestyle" for backward compatibility (and it is a nice convenience) but we don't need the middle-ground. |
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.
Looks good. Please add a What's New note according to https://matplotlib.org/devdocs/devel/api_changes.html#what-s-new-notes
`_val_or_rc` now accept multiple rc names and return val or the first non-None value in rcParams. Returns last rc name if all other are None. Also, simplified code in `Tick` for grid lines creatation
Do you want me to create the test in the file "test_rcparams.py" or create a separate file? |
Please put it in |
I was working on the test and I realised that the |
Then use |
I fix the spelling so all tests should pass now. If there is anything else please let me know. |
@timhoffm Any idea when this might be merged? |
This needs a second review by a core developer, and review time is scarce. However, this is flagged for 3.11 and I'm pretty sure it will get the attention in time for the next release. |
@QuLogic I have made the changes you suggested. If there is anything more I need to do, please let me know. |
stubtest is still complaining about |
Yes, I did it that way because this is how it is in the main branch. I never modified the function Do you want me to modify the function or revert the change in "ci/mypy-stubtest-allowlist.txt"? |
PR summary
Possibly closes #13919 issue. Additionally, PR #26121 also tried to solve the same issue but I understand that it is not backwards compatible and there haven't been any updates since 2023. My implementation should be backwards compatible.
I have tested the code with pytest. Some tests failed on my machine, but all were latex tests. The problem is probably my latex installation.
I also tested to code with a small python script that:
The results were identical and as expected.
Test
My test script:
Results
PR checklist