Thursday, 15 January 2015

python - Matplotlib: Getting different colors in data lines with error bars -



python - Matplotlib: Getting different colors in data lines with error bars -

i trying draw 2 info lines error bars, each having same color info line. however, lean line color have not specified in each info line when add together error bar.

also, create caps of error bars thicker alternative capthick not valid here.

could please help me prepare these issues?

this code.

import matplotlib.pyplot plt pylab import * import numpy np xaxis = [1, 2, 3] mean1 = [1,2,3.6] se1 = [0.2, 0.5, 0.9] mean2 = [10, 29, 14] se2 = [3, 4, 2] fig = plt.figure() ax = fig.add_subplot(111) ax.set_xlabel('x', fontsize = 16) ax.set_ylabel('y', fontsize = 16) ax.axis([0, 5, 0, 35]) ax.plot(xaxis, mean1, 'r--', linewidth = 4) ax.errorbar(xaxis, mean1, yerr = se1, ecolor = 'r', elinewidth = 2, capsize = 5) ax.plot(xaxis, mean2, 'b--', linewidth = 4) ax.errorbar(xaxis, mean2, yerr = se2, ecolor = 'b', elinewidth = 2, capsize = 5) plt.show()

the extra lean line coming errorbar() call.

errorbar draw line too, you're doing changing colour of error bars, not actual lines (hence using standard matplotlib first 2 colours, bluish , green.

it's in documentaion, here.

to accomplish want, need utilize errorbar() function;

this want think, maybe jsut tweak numbers bit.

import matplotlib.pyplot plt pylab import * import numpy np xaxis = [1, 2, 3] mean1 = [1,2,3.6] se1 = [0.2, 0.5, 0.9] mean2 = [10, 29, 14] se2 = [3, 4, 2] fig = plt.figure() ax = fig.add_subplot(111) ax.set_xlabel('x', fontsize = 16) ax.set_ylabel('y', fontsize = 16) ax.axis([0, 5, 0, 35]) linestyle = {"linestyle":"--", "linewidth":4, "markeredgewidth":5, "elinewidth":5, "capsize":10} ax.errorbar(xaxis, mean1, yerr = se1, color="r", **linestyle) ax.errorbar(xaxis, mean2, yerr = se2, color="b", **linestyle) plt.show()

i set mutual line style arguments dict gets unpacked.

python matplotlib figure

No comments:

Post a Comment