Skip to content
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

Legend color race condition #5242

Closed
jimrybarski opened this issue Oct 14, 2015 · 5 comments
Closed

Legend color race condition #5242

jimrybarski opened this issue Oct 14, 2015 · 5 comments

Comments

@jimrybarski
Copy link

The colors of the symbols in my legend vary randomly each time I make a plot or save it to disk. It shifts between a set of three colors, one of which is completely correct, one of which has a single incorrect color, and one which is all wrong. Run the demo code below several times to see this. I have reproduced this on two separate machines, one of which is running the code in a Docker container.

I have noticed the Please do not ask for support with these customizations active. but since it lists nothing, I'm not sure what to make of that.

matplotlib version: 1.4.3
backend: Qt5Agg version 5.3.2

import matplotlib.pyplot as plt
import random

blue = [.365, .647, .855]
green = [.376, .741, .408]
purple = [.698, .463, .698]


def boxplot(data, title, x_label, y_label, legend_location="upper left"):
    fig = plt.figure(1, figsize=(9, 6))
    ax = fig.add_subplot(111)
    meanprops = dict(linestyle='-', linewidth=1.5, color=purple)
    boxprops = dict(linewidth=1.5, color=blue)
    whiskerprops = dict(linewidth=1.5, color=blue)
    capprops = dict(linewidth=1.5, color=blue)
    medianprops = dict(alpha=0.0)
    flierprops = dict(marker='+', color=green, markersize=12, mew=2)

    plt.plot([], c=purple, label='Mean', linewidth=1.5)
    plt.plot([], c=blue, label='1st Quartile', linewidth=1.5)
    plt.plot([], c=blue, label='3rd Quartile', linewidth=1.5, linestyle='--')
    plt.legend(loc=legend_location, numpoints=1)
    plt.plot([], c=green, label='Outlier', marker='+', markersize=12, mew=2, linestyle='')
    plt.legend(loc=legend_location, numpoints=1)

    values = [a for d in data.values() for a in d]
    max_value = max(values)
    bp = ax.boxplot([d for n, d in sorted(data.items())],
                    meanprops=meanprops,
                    capprops=capprops,
                    flierprops=flierprops,
                    medianprops=medianprops,
                    boxprops=boxprops,
                    whiskerprops=whiskerprops,
                    showmeans=True,
                    meanline=True,
                    labels=[i for i in range(49)])
    ax.set_ylim([0, max_value + 2])
    ax.set_axis_bgcolor('white')
    ax.set_xlabel(x_label)
    ax.set_ylabel(y_label)
    plt.suptitle(title)
    fig = plt.gcf()
    fig.set_size_inches(20, 10)
    plt.show()
    plt.close()

if __name__ == '__main__':
    data = {j: [random.randint(10, 100) for i in range(100)] for j in range(49)}
    boxplot(data, "Race Condition Plots", "X Axis", "Y Axis")
$ python3.4 /opt/bug.py --verbose-helpful 

non-network local connections being added to access control list
$HOME=/root
matplotlib data path /usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data

*****************************************************************
You have the following UNSUPPORTED LaTeX preamble customizations:

Please do not ask for support with these customizations active.
*****************************************************************

loaded rc file /usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/matplotlibrc
matplotlib version 1.4.3
verbose.level helpful
interactive is False
platform is linux
CACHEDIR=/root/.cache/matplotlib
font search path ['/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf', '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/afm', '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/pdfcorefonts']
generated new fontManager
backend Qt5Agg version 5.3.2
1.4.3
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
Unrecognized line style none, <class 'str'>
libGL error: failed to open drm device: No such file or directory
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium to Bitstream Vera Sans ('/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf') with score of 0.000000
findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=large to Bitstream Vera Sans ('/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf') with score of 0.000000
@Tillsten
Copy link
Contributor

You are assigning a empty linestyl, is that wanted?

@jimrybarski
Copy link
Author

@Tillsten yes, since I only wanted to show a single marker for the outlier symbol, the line made no sense there. However, even if I add the line back in the color problem remains.

@tacaswell
Copy link
Member

As a side note, what is wrong with Axes.bxp / Axes.boxplot? Sorry. I can't read

@tacaswell
Copy link
Member

This is already fixed on master and will be released with 1.5.0 (there are rcs currently tagged, so soon).

As a work-around, for now use color=... instead of c=....

You also only need to call legend once.

@tacaswell
Copy link
Member

See #5197, #5199, #4162,

fixed by #4198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants