I'm trying to plot an errorbar
graph where each error bar may be either, say, red or green depending on whether the statistics used to compute the bar are significant.
I tried using an array of colors as an input to the c
parameter, but that didn't work.
Does anyone know how to do that?
Here is the code that I have so far:
yerrs = np.array([quantiles[:,2],quantiles[:,3]])
print yerrs.shape
colors = ['r', 'b'] * (yerrs.shape[1]/2)
fig, axes = plt.subplots(nrows=2, sharex=True, sharey=True)
axes[0].errorbar(quantiles[:,0],quantiles[:,1], yerr=yerrs, c=colors)
axes[0].axhline(0, color='black')
axes[0].axvline(0, color='black')
axes[0].set_title('Fitted dist')
I then get the error:
ValueError: to_rgba: Invalid rgba arg "['r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b']"
could not convert string to float: r
You can change the color of bars in a barplot using color argument. RGB is a way of making colors. You have to to provide an amount of red, green, blue, and the transparency value to the color argument and it returns a color.
Matplotlib PyPlot – Set Different Color(s) for Bars in Bar Plot. To set different colors for bars in a Bar Plot using Matplotlib PyPlot API, call matplotlib. pyplot. bar() function, and pass required color values, as list, to color parameter of bar() function.
The usual way to set the line color in matplotlib is to specify it in the plot command. This can either be done by a string after the data, e.g. "r-" for a red line, or by explicitely stating the color argument.
separate your data array into two groups and use "ecolor" to specify errorbar color.
axes[0].errorbar(x1, y1, yerr=yerr1, ecolor="r")
axes[0].errorbar(x2, y2, yerr=yerr2, ecolor="b")
How to separate data into portions 1 and 2 should be trivial to you, but let me know if you are uncertain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With