2017-11-23 23 views
-1

저는 파이썬에서 새롭고 아래 그림과 같이 한 줄에 여러 줄을 그려야합니다. 내가 시도파이썬에서 여러 줄을 그려야합니다.

enter image description here

은 다음과 같이 간단한 플로팅 코드를 작성 : enter image description here

내가 이러한 매개 변수

# red dashes, blue squares and green triangles 
    plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') 

알고하지만 같은 첫 번째 그림에 라인을 많이 가지고, 무엇을 첫 번째 그림처럼 플로팅에 사용할 수있는 매개 변수의 종류.

답변

1

MPL 라인 스타일과 마커를위한 많은 옵션이 있습니다 감사합니다. 보세요 here, herehere. 구체적인 예를 들어

는 (나는 빨리 일부 기능을 만들어 거의 처음 몇 가지 예를 꾸몄다) :

import matplotlib.pyplot as plt 
import numpy as np 

x=np.arange(6) 

fig=plt.figure() 
fig.show() 
ax=fig.add_subplot(111) 

ax.plot(x,x,c='b',marker="^",ls='--',label='GNE',fillstyle='none') 
ax.plot(x,x+1,c='g',marker=(8,2,0),ls='--',label='MMR') 
ax.plot(x,(x+1)**2,c='k',ls='-',label='Rand') 
ax.plot(x,(x-1)**2,c='r',marker="v",ls='-',label='GMC') 
ax.plot(x,x**2-1,c='m',marker="o",ls='--',label='BSwap',fillstyle='none') 
ax.plot(x,x-1,c='k',marker="+",ls=':',label='MSD') 

plt.legend(loc=2) 
plt.draw() 

이것은 당신이 뭔가를 제공해야합니다.

enter image description here

1

그런 다음, 먼저 그림을 정의 개별적으로 각각의 플롯을 정의 할 수 있습니다. 다음은 최소 예제 enter image description here입니다. 더 자세한 예제를 찾을 수 있습니다 here (단지 점을 중점적으로 다룹니다).

import numpy as np 
import matplotlib.pyplot as plt 

t = np.linspace(1, 10, 1000) 
plt.figure(figsize=(10, 6)) 
line1, = plt.plot(t, np.sin(t * 2 * np.pi), 'b-', label='$sin(t)$') 
line2, = plt.plot(t, np.cos(t * 2 * np.pi/2), 'r--', label='$sin(t)$') 
line3, = plt.plot(t, (np.sin(t * 2 * np.pi))**2, 'k.-', label='$sin(t)$') 

plt.legend(loc='upper right')