0
votes

In the following example the colour in the legend for data_3 will not appear as the same colour that is set in plt.errorbar([..],color='red'). Strangle this only applies to certain symbol and colour combinations. For example a red square will appear as a black square in the legend however a red circle will appear correctly in the legend. This seems to only be an issue when the legend is positioned outside the figure. Here is a worked example: import matplotlib.pyplot as plt import matplotlib import seaborn as sns sns.set() # set style of plots to seaborn

    matplotlib.rcParams['legend.handlelength'] = 0
    matplotlib.rcParams['legend.markerscale'] = 1

    labels = ['data_1','data_2','data_3','data_4']
    symbols = ['o','D','s','D']
    fill_style = ['none','full','none','full']
    colours = ['MediumPurple','Maroon','red','yellowGreen']

    x=range(10)
    y=range(10)

    for i in range(len(symbols)):
         plt.errorbar(x,[a+i*2 for a in y],elinewidth=1,color=colours[i],fmt=symbols[i],label=labels[i],ms=4,fillstyle=fill_style[i],markeredgewidth=1.75,markeredgecolor=colours[i])

    plt.legend(loc='center left',bbox_to_anchor=(1, 0.5)) 

results for above code

1
Can you show the figure where this is not showing as expected? Providing the figure of the expected result may be useful as well, but not on its own. - ImportanceOfBeingErnest
Actually, which browser are you using to view the notebook? Can you try with firefox? - ImportanceOfBeingErnest

1 Answers

0
votes

Just realised this is only a problem when displaying the figure in a jupyter notebook. When the figure is saved as either a .pdf or .png the legend entries all appear as they should, as you can see from the figure I provided!