Skip to content

BUG : Min/max markers on box plot are not visible with 'dark_background' (#40769) #41349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions pandas/tests/plotting/frame/test_frame_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -569,20 +575,20 @@ 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

# 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
Expand Down
33 changes: 33 additions & 0 deletions pandas/tests/plotting/test_boxplot_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'")],
Expand Down