From ccce7b48aa8bcf4a2513c8e776f8a41d9411b70c Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 11 Jun 2018 18:21:22 +0200 Subject: [PATCH] Backport PR #11409: plt.box_bug_fix --- lib/matplotlib/pyplot.py | 12 +++++++++--- lib/matplotlib/tests/test_pyplot.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 lib/matplotlib/tests/test_pyplot.py diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 613b1905089c..9c610372f633 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1354,17 +1354,23 @@ def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None): def box(on=None): """ - Turn the axes box on or off. + Turn the axes box on or off on the current axes. Parameters ---------- on : bool or None - The new axes box state. If ``None``, toggle the state. + The new `~matplotlib.axes.Axes` box state. If ``None``, toggle + the state. + + See Also + -------- + :meth:`matplotlib.axes.Axes.set_frame_on` + :meth:`matplotlib.axes.Axes.get_frame_on` """ ax = gca() - on = _string_to_bool(on) if on is None: on = not ax.get_frame_on() + on = _string_to_bool(on) ax.set_frame_on(on) diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py new file mode 100644 index 000000000000..f0442437682d --- /dev/null +++ b/lib/matplotlib/tests/test_pyplot.py @@ -0,0 +1,13 @@ +from matplotlib import pyplot as plt + + +def test_pyplot_box(): + fig, ax = plt.subplots() + plt.box(False) + assert not ax.get_frame_on() + plt.box(True) + assert ax.get_frame_on() + plt.box() + assert not ax.get_frame_on() + plt.box() + assert ax.get_frame_on()