Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab07898

Browse filesBrowse files
authored
Merge pull request #20173 from anntzer/gridb
Rename (with deprecation) first parameter of grid() from b to visible.
2 parents aec7ec8 + 4e2d5f4 commit ab07898
Copy full SHA for ab07898

File tree

Expand file treeCollapse file tree

6 files changed

+40
-48
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+40
-48
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The first parameter of ``Axes.grid`` and ``Axis.grid`` has been renamed to *visible*
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The parameter was previously named *b*. This deprecation only matters if
4+
that parameter was passed using a keyword argument, e.g. ``grid(b=False)``.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,17 +3191,18 @@ def set_axisbelow(self, b):
31913191
self.stale = True
31923192

31933193
@docstring.dedent_interpd
3194-
def grid(self, b=None, which='major', axis='both', **kwargs):
3194+
@_api.rename_parameter("3.5", "b", "visible")
3195+
def grid(self, visible=None, which='major', axis='both', **kwargs):
31953196
"""
31963197
Configure the grid lines.
31973198
31983199
Parameters
31993200
----------
3200-
b : bool or None, optional
3201-
Whether to show the grid lines. If any *kwargs* are supplied,
3202-
it is assumed you want the grid on and *b* will be set to True.
3201+
visible : bool or None, optional
3202+
Whether to show the grid lines. If any *kwargs* are supplied, it
3203+
is assumed you want the grid on and *visible* will be set to True.
32033204
3204-
If *b* is *None* and there are no *kwargs*, this toggles the
3205+
If *visible* is *None* and there are no *kwargs*, this toggles the
32053206
visibility of the lines.
32063207
32073208
which : {'major', 'minor', 'both'}, optional
@@ -3229,9 +3230,9 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
32293230
"""
32303231
_api.check_in_list(['x', 'y', 'both'], axis=axis)
32313232
if axis in ['x', 'both']:
3232-
self.xaxis.grid(b, which=which, **kwargs)
3233+
self.xaxis.grid(visible, which=which, **kwargs)
32333234
if axis in ['y', 'both']:
3234-
self.yaxis.grid(b, which=which, **kwargs)
3235+
self.yaxis.grid(visible, which=which, **kwargs)
32353236

32363237
def ticklabel_format(self, *, axis='both', style='', scilimits=None,
32373238
useOffset=None, useLocale=None, useMathText=None):

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+13-28Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,17 +1398,18 @@ def get_minor_ticks(self, numticks=None):
13981398

13991399
return self.minorTicks[:numticks]
14001400

1401-
def grid(self, b=None, which='major', **kwargs):
1401+
@_api.rename_parameter("3.5", "b", "visible")
1402+
def grid(self, visible=None, which='major', **kwargs):
14021403
"""
14031404
Configure the grid lines.
14041405
14051406
Parameters
14061407
----------
1407-
b : bool or None
1408-
Whether to show the grid lines. If any *kwargs* are supplied,
1409-
it is assumed you want the grid on and *b* will be set to True.
1408+
visible : bool or None
1409+
Whether to show the grid lines. If any *kwargs* are supplied, it
1410+
is assumed you want the grid on and *visible* will be set to True.
14101411
1411-
If *b* is *None* and there are no *kwargs*, this toggles the
1412+
If *visible* is *None* and there are no *kwargs*, this toggles the
14121413
visibility of the lines.
14131414
14141415
which : {'major', 'minor', 'both'}
@@ -1419,40 +1420,24 @@ def grid(self, b=None, which='major', **kwargs):
14191420
14201421
grid(color='r', linestyle='-', linewidth=2)
14211422
"""
1422-
TOGGLE = object()
1423-
UNSET = object()
1424-
visible = kwargs.pop('visible', UNSET)
1425-
1426-
if b is None:
1427-
if visible is UNSET:
1428-
if kwargs: # grid(color='r')
1429-
b = True
1430-
else: # grid()
1431-
b = TOGGLE
1432-
else: # grid(visible=v)
1433-
b = visible
1434-
else:
1435-
if visible is not UNSET and bool(b) != bool(visible):
1436-
# grid(True, visible=False), grid(False, visible=True)
1437-
raise ValueError(
1438-
"'b' and 'visible' specify inconsistent grid visibilities")
1439-
if kwargs and not b: # something false-like but not None
1440-
# grid(0, visible=True)
1423+
if kwargs:
1424+
if visible is None:
1425+
visible = True
1426+
elif not visible: # something false-like but not None
14411427
_api.warn_external('First parameter to grid() is false, '
14421428
'but line properties are supplied. The '
14431429
'grid will be enabled.')
1444-
b = True
1445-
1430+
visible = True
14461431
which = which.lower()
14471432
_api.check_in_list(['major', 'minor', 'both'], which=which)
14481433
gridkw = {'grid_' + item[0]: item[1] for item in kwargs.items()}
14491434
if which in ['minor', 'both']:
14501435
gridkw['gridOn'] = (not self._minor_tick_kw['gridOn']
1451-
if b is TOGGLE else b)
1436+
if visible is None else visible)
14521437
self.set_tick_params(which='minor', **gridkw)
14531438
if which in ['major', 'both']:
14541439
gridkw['gridOn'] = (not self._major_tick_kw['gridOn']
1455-
if b is TOGGLE else b)
1440+
if visible is None else visible)
14561441
self.set_tick_params(which='major', **gridkw)
14571442
self.stale = True
14581443

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,8 +2813,8 @@ def fill_betweenx(
28132813

28142814
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
28152815
@_copy_docstring_and_deprecators(Axes.grid)
2816-
def grid(b=None, which='major', axis='both', **kwargs):
2817-
return gca().grid(b=b, which=which, axis=axis, **kwargs)
2816+
def grid(visible=None, which='major', axis='both', **kwargs):
2817+
return gca().grid(visible=visible, which=which, axis=axis, **kwargs)
28182818

28192819

28202820
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.

‎lib/mpl_toolkits/axisartist/axislines.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axisartist/axislines.py
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,22 +528,23 @@ def cla(self):
528528
def get_grid_helper(self):
529529
return self._grid_helper
530530

531-
def grid(self, b=None, which='major', axis="both", **kwargs):
531+
@_api.rename_parameter("3.5", "b", "visible")
532+
def grid(self, visible=None, which='major', axis="both", **kwargs):
532533
"""
533534
Toggle the gridlines, and optionally set the properties of the lines.
534535
"""
535536
# There are some discrepancies in the behavior of grid() between
536537
# axes_grid and Matplotlib, because axes_grid explicitly sets the
537538
# visibility of the gridlines.
538-
super().grid(b, which=which, axis=axis, **kwargs)
539+
super().grid(visible, which=which, axis=axis, **kwargs)
539540
if not self._axisline_on:
540541
return
541-
if b is None:
542-
b = (self.axes.xaxis._minor_tick_kw["gridOn"]
543-
or self.axes.xaxis._major_tick_kw["gridOn"]
544-
or self.axes.yaxis._minor_tick_kw["gridOn"]
545-
or self.axes.yaxis._major_tick_kw["gridOn"])
546-
self.gridlines.set(which=which, axis=axis, visible=b)
542+
if visible is None:
543+
visible = (self.axes.xaxis._minor_tick_kw["gridOn"]
544+
or self.axes.xaxis._major_tick_kw["gridOn"]
545+
or self.axes.yaxis._minor_tick_kw["gridOn"]
546+
or self.axes.yaxis._major_tick_kw["gridOn"])
547+
self.gridlines.set(which=which, axis=axis, visible=visible)
547548
self.gridlines.set(**kwargs)
548549

549550
def get_children(self):

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,8 @@ def set_frame_on(self, b):
13711371
self._frameon = bool(b)
13721372
self.stale = True
13731373

1374-
def grid(self, b=True, **kwargs):
1374+
@_api.rename_parameter("3.5", "b", "visible")
1375+
def grid(self, visible=True, **kwargs):
13751376
"""
13761377
Set / unset 3D grid.
13771378
@@ -1383,8 +1384,8 @@ def grid(self, b=True, **kwargs):
13831384
"""
13841385
# TODO: Operate on each axes separately
13851386
if len(kwargs):
1386-
b = True
1387-
self._draw_grid = b
1387+
visible = True
1388+
self._draw_grid = visible
13881389
self.stale = True
13891390

13901391
def locator_params(self, axis='both', tight=None, **kwargs):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.