Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9c9b7a

Browse files
committed
Deprecate passing strings instead of booleans to control tick state.
Passing "off" or "false" to mean False is so MATLAB like...
1 parent f96fac0 commit c9c9b7a

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Using strings instead of booleans to control grid and tick visibility is deprecated
2+
```````````````````````````````````````````````````````````````````````````````````
3+
4+
Using ``"on"``, ``"off"``, ``"true"``, or ``"false"`` to control grid
5+
and tick visibility has been deprecated. Instead, use normal booleans
6+
(``True``/``False``) or boolean-likes. In the future, all non-empty strings
7+
may be interpreted as ``True``.

lib/matplotlib/axes/_base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,8 +2645,7 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
26452645
"""
26462646
Turn the axes grids on or off.
26472647
2648-
Set the axes grids on or off; *b* is a boolean. (For MATLAB
2649-
compatibility, *b* may also be a string, 'on' or 'off'.)
2648+
Set the axes grids on or off; *b* is a boolean.
26502649
26512650
If *b* is *None* and ``len(kwargs)==0``, toggle the grid state. If
26522651
*kwargs* are supplied, it is assumed that you want a grid and *b*
@@ -2861,12 +2860,11 @@ def tick_params(self, axis='both', **kwargs):
28612860
zorder : float
28622861
Tick and label zorder.
28632862
2864-
bottom, top, left, right : bool or {'on', 'off'}
2865-
controls whether to draw the respective ticks.
2863+
bottom, top, left, right : bool
2864+
Whether to draw the respective ticks.
28662865
2867-
labelbottom, labeltop, labelleft, labelright : bool or {'on', 'off'}
2868-
controls whether to draw the
2869-
respective tick labels.
2866+
labelbottom, labeltop, labelleft, labelright : bool
2867+
Whether to draw the respective tick labels.
28702868
28712869
labelrotation : float
28722870
Tick label rotation

lib/matplotlib/cbook/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ def _string_to_bool(s):
623623
"""Parses the string argument as a boolean"""
624624
if not isinstance(s, six.string_types):
625625
return bool(s)
626+
warn_deprecated("2.2", "Passing one of 'on', 'true', 'off', 'false' as a "
627+
"boolean is deprecated; use an actual boolean "
628+
"(True/False) instead.")
626629
if s.lower() in ['on', 'true']:
627630
return True
628631
if s.lower() in ['off', 'false']:

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,10 +1372,12 @@ def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None):
13721372

13731373
def box(on=None):
13741374
"""
1375-
Turn the axes box on or off. *on* may be a boolean or a string,
1376-
'on' or 'off'.
1375+
Turn the axes box on or off.
13771376
1378-
If *on* is *None*, toggle state.
1377+
Parameters
1378+
----------
1379+
on : bool or None
1380+
The new axes box state. If ``None``, toggle the state.
13791381
"""
13801382
ax = gca()
13811383
on = _string_to_bool(on)

0 commit comments

Comments
 (0)