Skip to content

Commit c19df34

Browse files
committed
DEPR: Change boxplot return_type kwarg
Part of #6581 Deprecation started in #7096 Changes the default value of `return_type` in DataFrame.boxplot and DataFrame.plot.box from None to 'axes'.
1 parent 4488f18 commit c19df34

File tree

5 files changed

+1048
-25
lines changed

5 files changed

+1048
-25
lines changed

doc/source/visualization.rst

+10-14
Original file line numberDiff line numberDiff line change
@@ -456,25 +456,21 @@ columns:
456456
457457
.. _visualization.box.return:
458458

459-
Basically, plot functions return :class:`matplotlib Axes <matplotlib.axes.Axes>` as a return value.
460-
In ``boxplot``, the return type can be changed by argument ``return_type``, and whether the subplots is enabled (``subplots=True`` in ``plot`` or ``by`` is specified in ``boxplot``).
459+
.. warning::
461460

462-
When ``subplots=False`` / ``by`` is ``None``:
461+
The default changed from ``'dict'`` to ``'axes'`` in version 0.18.0.
463462

464-
* if ``return_type`` is ``'dict'``, a dictionary containing the :class:`matplotlib Lines <matplotlib.lines.Line2D>` is returned. The keys are "boxes", "caps", "fliers", "medians", and "whiskers".
465-
This is the default of ``boxplot`` in historical reason.
466-
Note that ``plot.box()`` returns ``Axes`` by default same as other plots.
467-
* if ``return_type`` is ``'axes'``, a :class:`matplotlib Axes <matplotlib.axes.Axes>` containing the boxplot is returned.
468-
* if ``return_type`` is ``'both'`` a namedtuple containing the :class:`matplotlib Axes <matplotlib.axes.Axes>`
469-
and :class:`matplotlib Lines <matplotlib.lines.Line2D>` is returned
463+
Plot functions return scalar or arrays of :class:`matplotlib Axes <matplotlib.axes.Axes>`.
464+
In ``boxplot``, the return type can be controlled by the ``return_type``, keyword. The valid choices are ``{"axes", "dict", "both"}``. If the ``by`` argument is ``None``,
470465

471-
When ``subplots=True`` / ``by`` is some column of the DataFrame:
466+
* ``'axes'`` returns a single matplotlib axes.
467+
* ``'dict'`` returns a dict of matplotlib artists, similar to the matplotlib boxplot function.
468+
* ``'both'`` returns a named tuple of axes and dicts.
472469

473-
* A dict of ``return_type`` is returned, where the keys are the columns
474-
of the DataFrame. The plot has a facet for each column of
475-
the DataFrame, with a separate box for each value of ``by``.
470+
When ``by`` is not None, you get back an ``OrderedDict`` of whatever ``return_type`` is.
471+
Unless ``return_type`` is just ``None``, in which case you get back an array of axes.
476472

477-
Finally, when calling boxplot on a :class:`Groupby` object, a dict of ``return_type``
473+
Finally, when calling boxplot on a :class:`Groupby` object, an ``OrderedDict`` of ``return_type``
478474
is returned, where the keys are the same as the Groupby object. The plot has a
479475
facet for each key, with each facet containing a box for each column of the
480476
DataFrame.

doc/source/whatsnew/v0.18.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ Removal of prior version deprecations/changes
11681168
- Removal of ``rolling_corr_pairwise`` in favor of ``.rolling().corr(pairwise=True)`` (:issue:`4950`)
11691169
- Removal of ``expanding_corr_pairwise`` in favor of ``.expanding().corr(pairwise=True)`` (:issue:`4950`)
11701170
- Removal of ``DataMatrix`` module. This was not imported into the pandas namespace in any event (:issue:`12111`)
1171+
- Changed the default value for the ``return_type`` parameter for ``DataFrame.plot.box`` and ``DataFrame.boxplot`` from ``None`` to ``"axes"``. These methods will now return a matplotlib axes by default instead of a dictionary of artists. See :ref:`here <visualization.box.return>` (:issue:`6581`).
11711172
- Removal of ``cols`` keyword in favor of ``subset`` in ``DataFrame.duplicated()`` and ``DataFrame.drop_duplicates()`` (:issue:`6680`)
11721173
- Removal of the ``read_frame`` and ``frame_query`` (both aliases for ``pd.read_sql``)
11731174
and ``write_frame`` (alias of ``to_sql``) functions in the ``pd.io.sql`` namespace,

pandas/tests/plotting/test_frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,9 @@ def test_boxplot_return_type(self):
12211221
result = df.plot.box(return_type='axes')
12221222
self._check_box_return_type(result, 'axes')
12231223

1224+
result = df.plot.box() # default axes
1225+
self._check_box_return_type(result, 'axes')
1226+
12241227
result = df.plot.box(return_type='both')
12251228
self._check_box_return_type(result, 'both')
12261229

0 commit comments

Comments
 (0)