-
-
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?
Changes from 2 commits
bffeb0a
87726b6
e3d22aa
536b52e
397a2ad
87339d8
09a7346
42e0054
39eef79
a4e6f44
9a2b2b2
c886330
cd3c260
456034c
ca5a443
b455d6b
2cb99fc
6552586
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -124,16 +124,32 @@ def __init__( | |||||
zorder = mlines.Line2D.zorder | ||||||
self._zorder = zorder | ||||||
|
||||||
grid_color = mpl._val_or_rc(grid_color, "grid.color") | ||||||
grid_linestyle = mpl._val_or_rc(grid_linestyle, "grid.linestyle") | ||||||
grid_linewidth = mpl._val_or_rc(grid_linewidth, "grid.linewidth") | ||||||
grid_color = ( | ||||||
mpl._val_or_rc(grid_color, "grid.color") | ||||||
if mpl.rcParams[f"grid.{major_minor}.color"] == "none" | ||||||
else mpl._val_or_rc(grid_color, f"grid.{major_minor}.color") | ||||||
) | ||||||
grid_linestyle = ( | ||||||
mpl._val_or_rc(grid_linestyle, "grid.linestyle") | ||||||
if mpl.rcParams[f"grid.{major_minor}.linestyle"] == "none" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
see comment on validation |
||||||
else mpl._val_or_rc(grid_linestyle, f"grid.{major_minor}.linestyle") | ||||||
) | ||||||
grid_linewidth = ( | ||||||
mpl._val_or_rc(grid_linewidth, "grid.linewidth") | ||||||
if mpl.rcParams[f"grid.{major_minor}.linewidth"] is None | ||||||
else mpl._val_or_rc(grid_linewidth, f"grid.{major_minor}.linewidth") | ||||||
) | ||||||
if grid_alpha is None and not mcolors._has_alpha_channel(grid_color): | ||||||
# alpha precedence: kwarg > color alpha > rcParams['grid.alpha'] | ||||||
# Note: only resolve to rcParams if the color does not have alpha | ||||||
# otherwise `grid(color=(1, 1, 1, 0.5))` would work like | ||||||
# grid(color=(1, 1, 1, 0.5), alpha=rcParams['grid.alpha']) | ||||||
# so the that the rcParams default would override color alpha. | ||||||
grid_alpha = mpl.rcParams["grid.alpha"] | ||||||
grid_alpha = ( | ||||||
mpl.rcParams["grid.alpha"] | ||||||
if f"grid.{major_minor}.alpha" not in mpl.rcParams | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the logic here different (hasattr) compared to the other parameters (is None)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I have no idea so the only explanation is stupidity. Furthermore, I think this is a bug because grid.minor/major.alpha is always in |
||||||
else mpl.rcParams[f"grid.{major_minor}.alpha"] | ||||||
) | ||||||
grid_kw = {k[5:]: v for k, v in kwargs.items()} | ||||||
|
||||||
self.tick1line = mlines.Line2D( | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1237,6 +1237,16 @@ def _convert_validator_spec(key, conv): | |
"grid.linewidth": validate_float, # in points | ||
"grid.alpha": validate_float, | ||
|
||
"grid.major.color": validate_color, # grid color | ||
"grid.major.linestyle": _validate_linestyle, # solid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to be a bit more precise with these. The string "none" is a valid value for both. We should not repurpose it here with the meaning not defined. In the parsed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I was thinking of doing something like that but I saw that the functions parse the "None" and "none", so I didn't know if I should introduce a new function or not. Nevertheless, this should be easy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it’s a bit unfortunate 67E6 that the existing parameters are permissive wrt. to capitalization. But the new ones have to distinguish. We may deprecate accepting None for the other variants. But that’d be for a separate PR. |
||
"grid.major.linewidth": validate_float_or_None, # in points | ||
"grid.major.alpha": validate_float_or_None, | ||
|
||
"grid.minor.color": validate_color, # grid color | ||
"grid.minor.linestyle": _validate_linestyle, # solid | ||
"grid.minor.linewidth": validate_float_or_None, # in points | ||
"grid.minor.alpha": validate_float_or_None, | ||
|
||
## figure props | ||
# figure title | ||
"figure.titlesize": validate_fontsize, | ||
|
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.
see comment on validation