Skip to content

Min/max markers on box plot are not visible with 'dark_background' theme #19778

Closed
@sandyscott

Description

@sandyscott

Min/max markers on box plot are not visible with 'dark_background' theme

The min & max markers (the short lines at the ends of the whiskers) aren't visible with the 'dark_background' theme

Code for reproduction

import pandas as pd
import matplotlib.pyplot as plt

# Data is from the pandas plotting demo
# https://pandas.pydata.org/docs/getting_started/intro_tutorials/04_plotting.html
air_quality = pd.read_csv("air_quality_no2.csv", index_col=0, parse_dates=True)

plt.style.use('default')
air_quality.plot.box()

plt.style.use('dark_background')
air_quality.plot.box()

Actual outcome

boxplot_issue

Software versions

  • Matplotlib version: 3.3.1
  • Matplotlib backend: module://ipykernel.pylab.backend_inline
  • Python version: 3.8.6
  • Jupyterlab version: 3.0.12
  • Pandas: 1.2.3
  • Operating system: Sage Math 9.2 installation running on Ubuntu 20.10 on WSL in windows 10 64-bit

Activity

diegopetrola

diegopetrola commented on Mar 31, 2021

@diegopetrola
Contributor

I tried to reproduce this somehow using only matplotlib and numpy and was unable to.
Here is an exemple code:

#Code taken from matplotlib.org/stable/gallery/index.html#
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

plt.style.use('dark_background')
# Fixing random state for reproducibility
np.random.seed(19680801)

# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low))

fig1, ax1 = plt.subplots()
ax1.set_title('Basic Plot')
ax1.boxplot(data)

And the outcome is:
image

I also briefly investigated pandas and it seems they have a function called _get_standard_colors() in line 83 of the script called boxplot.py. I am fairly confident that it is this function that overrides the theme and causes the issue.

If you manage to reproduce this without using pandas, please let us know but, as of now, I believe the issue should be redirected to them.

For now you can change the last line of your code to air_quality.plot.box(capprops=dict(color='white')) or any other color you like to have the markers appear in the figure. If you want further information on how to customize the colors of a boxplot you can read more here.

jklymak

jklymak commented on Mar 31, 2021

@jklymak
Member

Thanks @diegopetrola, I'll close this.

sandyscott

sandyscott commented on Apr 3, 2021

@sandyscott
Author

Thank you, I've reported the issue in pandas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @QuLogic@jklymak@sandyscott@diegopetrola

        Issue actions

          Min/max markers on box plot are not visible with 'dark_background' theme · Issue #19778 · matplotlib/matplotlib