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()