From b994fd2699509943920a376c66bb5eba33100728 Mon Sep 17 00:00:00 2001 From: Yeshwanth N Date: Thu, 6 May 2021 15:22:09 +0530 Subject: [PATCH 1/3] BUG : Fixing - Min/max markers on box plot are not visible with 'dark_background' (#40769) --- doc/source/whatsnew/v1.3.0.rst | 1 + pandas/plotting/_matplotlib/boxplot.py | 2 +- .../tests/plotting/frame/test_frame_color.py | 14 +++++--- pandas/tests/plotting/test_boxplot_method.py | 33 +++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index a81dda4e7dfdd..c765025ef6e0e 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -849,6 +849,7 @@ Plotting - Prevent warnings when matplotlib's ``constrained_layout`` is enabled (:issue:`25261`) - Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``yerr`` while others didn't (partial fix of :issue:`39522`) - Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``secondary_y`` and others use ``legend=False`` (:issue:`40044`) +- Bug in :meth:`BoxPlot._validate_color_args` in box plot when 'dark_background' theme was selected, caps or min/max markers for the plot was not visible (:issue:`40769`) Groupby/resample/rolling diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index 6a81e3ae43b5d..21f30c1311e17 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -101,7 +101,7 @@ def _validate_color_args(self): self._boxes_c = colors[0] self._whiskers_c = colors[0] self._medians_c = colors[2] - self._caps_c = "k" # mpl default + self._caps_c = colors[0] def _get_colors(self, num_colors=None, color_kwds="color"): pass diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 6844124d15f9d..a9b691f2a42b9 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -546,7 +546,13 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None): df = DataFrame(np.random.randn(5, 5)) bp = df.plot.box(return_type="dict") - _check_colors(bp, default_colors[0], default_colors[0], default_colors[2]) + _check_colors( + bp, + default_colors[0], + default_colors[0], + default_colors[2], + default_colors[0], + ) tm.close() dict_colors = { @@ -569,7 +575,7 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None): # partial colors dict_colors = {"whiskers": "c", "medians": "m"} bp = df.plot.box(color=dict_colors, return_type="dict") - _check_colors(bp, default_colors[0], "c", "m") + _check_colors(bp, default_colors[0], "c", "m", default_colors[0]) tm.close() from matplotlib import cm @@ -577,12 +583,12 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None): # Test str -> colormap functionality bp = df.plot.box(colormap="jet", return_type="dict") jet_colors = [cm.jet(n) for n in np.linspace(0, 1, 3)] - _check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2]) + _check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2], jet_colors[0]) tm.close() # Test colormap functionality bp = df.plot.box(colormap=cm.jet, return_type="dict") - _check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2]) + _check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2], jet_colors[0]) tm.close() # string color is applied to all artists except fliers diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 448679d562a4a..dbceeae44a493 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -195,6 +195,39 @@ def test_color_kwd(self, colors_kwd, expected): for k, v in expected.items(): assert result[k][0].get_color() == v + @pytest.mark.parametrize( + "scheme,expected", + [ + ( + "dark_background", + { + "boxes": "#8dd3c7", + "whiskers": "#8dd3c7", + "medians": "#bfbbd9", + "caps": "#8dd3c7", + }, + ), + ( + "default", + { + "boxes": "#1f77b4", + "whiskers": "#1f77b4", + "medians": "#2ca02c", + "caps": "#1f77b4", + }, + ), + ], + ) + def test_colors_in_theme(self, scheme, expected): + # GH: 40769 + df = DataFrame(np.random.rand(10, 2)) + import matplotlib.pyplot as plt + + plt.style.use(scheme) + result = df.plot.box(return_type="dict") + for k, v in expected.items(): + assert result[k][0].get_color() == v + @pytest.mark.parametrize( "dict_colors, msg", [({"boxes": "r", "invalid_key": "r"}, "invalid key 'invalid_key'")], From 68ca5883455a731c1ca389da8c98e5a338f9695d Mon Sep 17 00:00:00 2001 From: Yeshwanth N Date: Sun, 9 May 2021 19:56:36 +0530 Subject: [PATCH 2/3] DOC : Replace method path with uesr friendly version (#40769) --- doc/source/whatsnew/v1.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index c765025ef6e0e..4e256f96609c0 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -849,7 +849,7 @@ Plotting - Prevent warnings when matplotlib's ``constrained_layout`` is enabled (:issue:`25261`) - Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``yerr`` while others didn't (partial fix of :issue:`39522`) - Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``secondary_y`` and others use ``legend=False`` (:issue:`40044`) -- Bug in :meth:`BoxPlot._validate_color_args` in box plot when 'dark_background' theme was selected, caps or min/max markers for the plot was not visible (:issue:`40769`) +- Bug in :meth:`DataFrame.plot.box` in box plot when 'dark_background' theme was selected, caps or min/max markers for the plot was not visible (:issue:`40769`) Groupby/resample/rolling From 82884e53e5d200adb553be70ec2e262baaef1610 Mon Sep 17 00:00:00 2001 From: Yeshwanth N Date: Mon, 10 May 2021 09:11:37 +0530 Subject: [PATCH 3/3] DOC : Formatting change in whatsnew note (#40769) --- doc/source/whatsnew/v1.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 4e256f96609c0..84144f234d7a9 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -849,7 +849,7 @@ Plotting - Prevent warnings when matplotlib's ``constrained_layout`` is enabled (:issue:`25261`) - Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``yerr`` while others didn't (partial fix of :issue:`39522`) - Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``secondary_y`` and others use ``legend=False`` (:issue:`40044`) -- Bug in :meth:`DataFrame.plot.box` in box plot when 'dark_background' theme was selected, caps or min/max markers for the plot was not visible (:issue:`40769`) +- Bug in :meth:`DataFrame.plot.box` in box plot when ``dark_background`` theme was selected, caps or min/max markers for the plot was not visible (:issue:`40769`) Groupby/resample/rolling