我正在通过matplotlib / pyplot进行绘图。为什么星形和圆形的初始点(蓝色)将一条线连接到最终点?初始点星连接最终点圆,初始点圆连接最终点平方。
这是源代码:
plt.plot(x,y, color="black")
plt.errorbar(x1,y1,yerr=err1,marker='s', markersize="10", mfc='blue', color='blue',fmt = '')
plt.errorbar(x2,y2,yerr=err2,marker='s', markersize="10", mfc='green', color='green',fmt = '')
plt.errorbar(x3,y3,yerr=err3,marker='s', markersize="10", mfc='red', color='red',fmt = '')
plt.errorbar(x4,y4,yerr=err4,marker='s', markersize="10", mfc='yellow', color='yellow',fmt = '')
plt.errorbar(x5,y5,yerr=err5,marker='s', markersize="10", mfc='orange', color='orange',fmt = '')
plt.errorbar(x6,y6,yerr=err6,marker='s', markersize="10", mfc='purple', color='purple',fmt = '')
plt.errorbar(x7,y7,yerr=err7,marker='s', markersize="10", mfc='magenta', color='magenta',fmt = '')
plt.errorbar(x8,y8,yerr=err8,marker='s', markersize="10", mfc='cyan', color='cyan',fmt = '')
plt.errorbar(x9,y9,yerr=err9,marker='o', markersize="10", mfc='blue', color='blue',fmt = '')
plt.errorbar(x10,y10,yerr=err10,marker='o', markersize="10", mfc='green', color='green',fmt = '')
plt.errorbar(x11,y11,yerr=err11,marker='o', markersize="10", mfc='red', color='red',fmt = '')
plt.errorbar(x12,y12,yerr=err12,marker='o', markersize="10", mfc='yellow', color='yellow',fmt = '')
plt.errorbar(x13,y13,yerr=err13,marker='o', markersize="10", mfc='orange', color='orange',fmt = '')
plt.errorbar(x14,y14,yerr=err14,marker='o', markersize="10", mfc='purple', color='purple',fmt = '')
plt.errorbar(x15,y15,yerr=err15,marker='o', markersize="10", mfc='magenta', color='magenta',fmt = '')
plt.errorbar(x16,y16,yerr=err16,marker='o', markersize="10", mfc='cyan', color='cyan',fmt = '')
plt.errorbar(x17,y17,yerr=err17,marker='*', markersize="10", mfc='blue', color='blue',fmt = '')
plt.errorbar(x18,y18,yerr=err18,marker='*', markersize="10", mfc='green', color='green',fmt = '')
plt.errorbar(x19,y19,yerr=err19,marker='*', markersize="10", mfc='red', color='red',fmt = '')
plt.errorbar(x20,y20,yerr=err20,marker='*', markersize="10", mfc='yellow', color='yellow',fmt = '')
plt.errorbar(x21,y21,yerr=err21,marker='*', markersize="10", mfc='orange', color='orange',fmt = '')
plt.errorbar(x22,y22,yerr=err22,marker='*', markersize="10", mfc='purple', color='purple',fmt = '')
plt.errorbar(x23,y23,yerr=err23,marker='*', markersize="10", mfc='magenta', color='magenta',fmt = '')
plt.errorbar(x24,y24,yerr=err24,marker='*', markersize="10", mfc='cyan', color='cyan',fmt = '')
plt.savefig("image.png",bbox_inches='tight')
plt.show()
“x”变量是形状24阵列。 “y”变量是形状24阵列 “错误”变量只是实数。
答案 0 :(得分:1)
如果你想绘制三条独立的线,每条线有八个点,你就不能一次性绘制它们。使用两个长度为24的数组。相反,将数据拆分为三个单独的和平并分别绘制它们:
plot(x[0:8],y[0:8],'black')
plot(x[8:16],y[8:16],'black')
plot(x[16:24],y[16:24],'black')
这应该可以解决问题。另请注意,您可以使用errorbar
和lists
语句大大缩短for
代码。例如,你可以做
errs = [err1,err2,err3,err4,err5,err6,err7,err8] #probably you did have these in a list or array anyway
cols = ['b','g','r','y','orange','purple','m','c']
for i,(errval,col) in enumerate(zip(errs,cols)):
plt.errorbar(x[i],y[i],yerr=errvall, marker='s', markersize="10", mfc=col, color=col,fmt = '')
使用另一个for
循环,您仍然可以遍历markers
。希望这会有所帮助。