patche를 사용하지 않으려는 경우 타원의 매개 변수 방정식을 사용할 수 있습니다. x = u + a.cos (t); 범 Y = V + b.sin (t)
import numpy as np
from matplotlib import pyplot as plt
from math import pi
u=1. #x-position of the center
v=0.5 #y-position of the center
a=2. #radius on the x-axis
b=1.5 #radius on the y-axis
t = np.linspace(0, 2*pi, 100)
plt.plot(u+a*np.cos(t) , v+b*np.sin(t))
plt.grid(color='lightgray',linestyle='--')
plt.show()
:
타원는 2D 회전 행렬 덕분 회전 수
import numpy as np
from matplotlib import pyplot as plt
from math import pi, cos, sin
u=1. #x-position of the center
v=0.5 #y-position of the center
a=2. #radius on the x-axis
b=1.5 #radius on the y-axis
t_rot=pi/4 #rotation angle
t = np.linspace(0, 2*pi, 100)
Ell = np.array([a*np.cos(t) , b*np.sin(t)])
#u,v removed to keep the same center location
R_rot = np.array([[cos(t_rot) , -sin(t_rot)],[sin(t_rot) , cos(t_rot)]])
#2-D rotation matrix
Ell_rot = np.zeros((2,Ell.shape[1]))
for i in range(Ell.shape[1]):
Ell_rot[:,i] = np.dot(R_rot,Ell[:,i])
plt.plot(u+Ell[0,:] , v+Ell[1,:]) #initial ellipse
plt.plot(u+Ell_rot[0,:] , v+Ell_rot[1,:],'darkorange') #rotated ellipse
plt.grid(color='lightgray',linestyle='--')
plt.show()
결과 : ![rotated ellipse with parametric equation](https://i.stack.imgur.com/0MJId.png)
을 나는 표준 플로팅 방법에 더 가까운 것을 기대했지만, 다음으로 살펴 보겠습니다. 감사! – casper
matplotlib.pyplot에서 무언가를 찾고있는 것으로 나타났습니다. 죄송합니다. 처음에는 그걸 알지 못했습니다. 'matplotlib.pyplot' API 문서를 검색해도 아무 것도 밝혀지지 않았기 때문에'matplotlib.patches.Ellipse'를 사용하여 살아야 할 것 같습니다. – Chris
고마워요, 그렇게해야 할 것 같습니다. 필자는 pyplot에 기본적인 모양을 그리는 기능을 포함 시키려고했지만 모든 것을 가질 수는 없다고 생각합니다. – casper