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()
: 楕円は2次元回転行列のおかげで回転させることができる。
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()
戻り値:
を標準のプロット方法に近いものを望んでいましたが、次にこれを見ていきます。ありがとう! – casper
matplotlib.pyplotで何かを探していることに気がつきました。申し訳ありませんが、それに気付かなかったからです。 'matplotlib.pyplot' APIドキュメントを検索しても何も明らかにならないので、' matplotlib.patches.Ellipse'を使って暮らす必要があります。 – Chris
ありがとう、それは私がしなければならないことです。私はpyplotにいくつかの基本的な形状プロット機能を含めることを期待していましたが、すべてを持つことはできません! – casper