|
12 | 12 | from matplotlib import _api
|
13 | 13 | import matplotlib.artist as martist
|
14 | 14 | import matplotlib.cbook as cbook
|
| 15 | +import matplotlib.colors as mcolors |
15 | 16 | import matplotlib.lines as mlines
|
16 | 17 | import matplotlib.scale as mscale
|
17 | 18 | import matplotlib.text as mtext
|
@@ -143,7 +144,12 @@ def __init__(
|
143 | 144 | grid_linestyle = mpl.rcParams["grid.linestyle"]
|
144 | 145 | if grid_linewidth is None:
|
145 | 146 | grid_linewidth = mpl.rcParams["grid.linewidth"]
|
146 |
| - if grid_alpha is None: |
| 147 | + if grid_alpha is None and not mcolors._has_alpha_channel(grid_color): |
| 148 | + # alpha precedence: kwarg > color alpha > rcParams['grid.alpha'] |
| 149 | + # Note: only resolve to rcParams if the color does not have alpha |
| 150 | + # otherwise `grid(color=(1, 1, 1, 0.5))` would work like |
| 151 | + # grid(color=(1, 1, 1, 0.5), alpha=rcParams['grid.alpha']) |
| 152 | + # so the that the rcParams default would override color alpha. |
147 | 153 | grid_alpha = mpl.rcParams["grid.alpha"]
|
148 | 154 | grid_kw = {k[5:]: v for k, v in kwargs.items()}
|
149 | 155 |
|
@@ -1498,7 +1504,7 @@ def grid(self, visible=None, which='major', **kwargs):
|
1498 | 1504 | visible = True
|
1499 | 1505 | which = which.lower()
|
1500 | 1506 | _api.check_in_list(['major', 'minor', 'both'], which=which)
|
1501 |
| - gridkw = {'grid_' + item[0]: item[1] for item in kwargs.items()} |
| 1507 | + gridkw = {f'grid_{name}': value for name, value in kwargs.items()} |
1502 | 1508 | if which in ['minor', 'both']:
|
1503 | 1509 | gridkw['gridOn'] = (not self._minor_tick_kw['gridOn']
|
1504 | 1510 | if visible is None else visible)
|
|
0 commit comments