Skip to content

Commit c681791

Browse files
authored
BUG : Min/max markers on box plot are not visible with 'dark_background' (#40769) (#41349)
* BUG : Fixing - Min/max markers on box plot are not visible with 'dark_background' (#40769) * DOC : Replace method path with uesr friendly version (#40769) * DOC : Formatting change in whatsnew note (#40769)
1 parent 67c9385 commit c681791

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ Plotting
851851
- Prevent warnings when matplotlib's ``constrained_layout`` is enabled (:issue:`25261`)
852852
- 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`)
853853
- 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`)
854+
- 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`)
854855

855856

856857
Groupby/resample/rolling

pandas/plotting/_matplotlib/boxplot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _validate_color_args(self):
101101
self._boxes_c = colors[0]
102102
self._whiskers_c = colors[0]
103103
self._medians_c = colors[2]
104-
self._caps_c = "k" # mpl default
104+
self._caps_c = colors[0]
105105

106106
def _get_colors(self, num_colors=None, color_kwds="color"):
107107
pass

pandas/tests/plotting/frame/test_frame_color.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,13 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None):
546546

547547
df = DataFrame(np.random.randn(5, 5))
548548
bp = df.plot.box(return_type="dict")
549-
_check_colors(bp, default_colors[0], default_colors[0], default_colors[2])
549+
_check_colors(
550+
bp,
551+
default_colors[0],
552+
default_colors[0],
553+
default_colors[2],
554+
default_colors[0],
555+
)
550556
tm.close()
551557

552558
dict_colors = {
@@ -569,20 +575,20 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None):
569575
# partial colors
570576
dict_colors = {"whiskers": "c", "medians": "m"}
571577
bp = df.plot.box(color=dict_colors, return_type="dict")
572-
_check_colors(bp, default_colors[0], "c", "m")
578+
_check_colors(bp, default_colors[0], "c", "m", default_colors[0])
573579
tm.close()
574580

575581
from matplotlib import cm
576582

577583
# Test str -> colormap functionality
578584
bp = df.plot.box(colormap="jet", return_type="dict")
579585
jet_colors = [cm.jet(n) for n in np.linspace(0, 1, 3)]
580-
_check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2])
586+
_check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2], jet_colors[0])
581587
tm.close()
582588

583589
# Test colormap functionality
584590
bp = df.plot.box(colormap=cm.jet, return_type="dict")
585-
_check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2])
591+
_check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2], jet_colors[0])
586592
tm.close()
587593

588594
# string color is applied to all artists except fliers

pandas/tests/plotting/test_boxplot_method.py

+33
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,39 @@ def test_color_kwd(self, colors_kwd, expected):
195195
for k, v in expected.items():
196196
assert result[k][0].get_color() == v
197197

198+
@pytest.mark.parametrize(
199+
"scheme,expected",
200+
[
201+
(
202+
"dark_background",
203+
{
204+
"boxes": "#8dd3c7",
205+
"whiskers": "#8dd3c7",
206+
"medians": "#bfbbd9",
207+
"caps": "#8dd3c7",
208+
},
209+
),
210+
(
211+
"default",
212+
{
213+
"boxes": "#1f77b4",
214+
"whiskers": "#1f77b4",
215+
"medians": "#2ca02c",
216+
"caps": "#1f77b4",
217+
},
218+
),
219+
],
220+
)
221+
def test_colors_in_theme(self, scheme, expected):
222+
# GH: 40769
223+
df = DataFrame(np.random.rand(10, 2))
224+
import matplotlib.pyplot as plt
225+
226+
plt.style.use(scheme)
227+
result = df.plot.box(return_type="dict")
228+
for k, v in expected.items():
229+
assert result[k][0].get_color() == v
230+
198231
@pytest.mark.parametrize(
199232
"dict_colors, msg",
200233
[({"boxes": "r", "invalid_key": "r"}, "invalid key 'invalid_key'")],

0 commit comments

Comments
 (0)