2017-09-07 6 views
1

matplotlib/pyplot을 통해 플로팅 중입니다. 별과 원의 초기 점 (파란색)이 왜 선을 최종 점에 연결하고 있습니까? 초기 점 별이 마지막 점 원을 연결하고 있고, 초기 점 원이 최종 점 사각형을 연결하고 있습니다.Matplotlib - 연결 지점이 잘못되었습니다.

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 배열입니다. "err"변수는 단지 실수입니다. 각, 당신은 대신 길이 (24)의 두 배열을 사용하여 '번'을 그릴 수 8 점의 세 개의 라인을 플롯하려면

enter image description here

+0

정확하게 이해한다면 세 개의 데이터 시리즈가 있습니다. 하나는 정사각형 포인트, 하나는 라운드 포인트, 다른 하나는 별점입니다. 이 경우 3 개의 시리즈를 각각 별도로 플롯해야하지만, 지금 당장에는 그렇게 할 수 있습니다 (앞에서 말했듯이 길이가 24 인 배열 두 개가 있습니다). plot 명령을 다음과 같이 세 가지로 나누십시오 : plot (x [8 : 16], y [8:16], '흑인')'그리고 나서'plot (x [16:24], y [16:24], 'black')'- 이것은 당신의 문제를 해결할 것입니다. –

+0

네, 효과가있었습니다! 감사! 대답으로 게시하십시오. 그러면 솔루션으로 표시됩니다. – Marco

답변

1

는 3 개의 별도의 peaces로 데이터를 분할하여 별도로 음모 :

plot(x[0:8],y[0:8],'black') 
plot(x[8:16],y[8:16],'black') 
plot(x[16:24],y[16:24],'black') 

이 트릭을 수행해야합니다. 또한 listsfor 문을 사용하여 코드을 상당히 단축 할 수 있습니다. 예를 들어 다른 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 = '') 

을 할 수있는 당신은 수 여전히 markers을 통해 루프. 희망이 도움이됩니다.

관련 문제