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

Skip to content

Commit a919d79

Browse files
authored
Merge pull request #10089 from anntzer/tick-booleans
Deprecate passing strings instead of booleans to control tick state (and other states).
2 parents 372d5d8 + c9c9b7a commit a919d79

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed
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
@@ -2618,8 +2618,7 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
26182618
"""
26192619
Turn the axes grids on or off.
26202620
2621-
Set the axes grids on or off; *b* is a boolean. (For MATLAB
2622-
compatibility, *b* may also be a string, 'on' or 'off'.)
2621+
Set the axes grids on or off; *b* is a boolean.
26232622
26242623
If *b* is *None* and ``len(kwargs)==0``, toggle the grid state. If
26252624
*kwargs* are supplied, it is assumed that you want a grid and *b*
@@ -2834,12 +2833,11 @@ def tick_params(self, axis='both', **kwargs):
28342833
zorder : float
28352834
Tick and label zorder.
28362835
2837-
bottom, top, left, right : bool or {'on', 'off'}
2838-
controls whether to draw the respective ticks.
2836+
bottom, top, left, right : bool
2837+
Whether to draw the respective ticks.
28392838
2840-
labelbottom, labeltop, labelleft, labelright : bool or {'on', 'off'}
2841-
controls whether to draw the
2842-
respective tick labels.
2839+
labelbottom, labeltop, labelleft, labelright : bool
2840+
Whether to draw the respective tick labels.
28432841
28442842
labelrotation : float
28452843
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)