Matplotlib Errorbar Plot - Using A Custom Colormap
I'm trying to make an errorbar plot with different colors for each point along the x axis. The errorbar chart itself is coming out fine, but it bombs when I try to use a colormap,
Solution 1:
I already mentioned that you can loop over each particular point/color.
Another solution is to use a scatter
plot within your errorbar
plot, like in this question. The code is below
import matplotlib.pyplot as pltcolors= ["b","g","c","m","y","k","r","g","c","m","y","k",
"b","g","c","m","y","k","r","g","c","m","y","k"]
xlabels = ['A','B','8','14']
xval = [0, 1, 2, 3]
yval = [0, 1, 4, 9]
yerr = [0.5, 0.4, 0.6, 0.9]
plt.scatter(xval, yval, c=colors, s=50, zorder=3)
plt.errorbar(xval, yval, yerr=yerr, zorder=0, fmt="none",
marker="none")
plt.savefig("scatter_error.png", dpi=300)
plt.show()
With the following result
Post a Comment for "Matplotlib Errorbar Plot - Using A Custom Colormap"