How do you change the colors of individual markers with matplotlib.errorbar?

Viewed 2662

I'm making a scatterplot with error bars, and so far my code looks like this:

plt.errorbar(indices,
                 sample_means,
                 xerr=0,
                 yerr=yerr,
                 marker='o',
                 markeredgecolor='blue',
                 markerfacecolor='blue',
                 Linestyle='None',
                 ecolor=ecolor
                )

Here ecolor is an array that can be something like np.array(['red','blue','green']). This controls the colors of the error bars, but I want the data markers to be those same colors as well. markeredgecolor and markerfacecolor don't seem to take arrays as values. Is there any way to make the data markers these colors as well?

1 Answers

plt.errorbar() can take argument 'c', which can be any of the following:

A scalar or sequence of n numbers to be mapped to colors using cmap and norm.

A 2-D array in which the rows are RGB or RGBA.

A sequence of colors of length n.

A single color format string.

The below code will make the points of your plot black while not changing the color of anything else:

plt.errorbar(indices,
             sample_means,
             xerr=0,
             yerr=yerr,
             marker='o',
             markeredgecolor='blue',
             markerfacecolor='blue',
             Linestyle='None',
             ecolor=ecolor,
             c='black'
            )
Related