我想从代码中给出的半主要和半小数组对创建椭圆图,如x和y。到目前为止,我只能从x和y的单个数组值创建单个图。如何从所有x和y值绘制椭圆?
import numpy as np
import pandas as pd
import math as m
import matplotlib.patches as patches
import matplotlib.pyplot as plt
x1=6.5 #Approach distane measurement point
y1=0.45 #Lateral distance measurement point
Nx=np.linspace(80,60,10)
Ny=np.linspace(80,60,10)
c=20
a=(10**(Nx/c))
b=(10**(86/20))
x=x1*(a/b) #semi major axis
#rx=x*m.cos(m.radians(45))
a=(10**(Ny/c))
b=(10**(83/20))
y=y1*(a/b) #semi mionr axis
#ry=y*m.cos(m.radians(45))
resolution = 1000
t = np.linspace(0, 2*np.pi, resolution)
xr = x[5] * np.cos(t) * np.cos(m.radians(0)) - y[5] * np.sin(t) * np.sin(m.radians(0))
yr = y[5] * np.sin(t) * np.cos(m.radians(0)) + x[5]* np.cos(t) * np.sin(m.radians(0))
plt.plot(xr, yr)
print x
答案 0 :(得分:1)
如果我正确理解你的问题,你可以创建半长轴和半短轴对的数组,并且想要为每对绘制轮廓。
在您的代码中,为什么只使用索引来循环遍历所有元素时,为什么只使用x [5]和y [5]?
for i in range(10):
xr = x[i] * np.cos(t) * np.cos(m.radians(0)) - y[i] * np.sin(t) * np.sin(m.radians(0))
yr = y[i] * np.sin(t) * np.cos(m.radians(0)) + x[i]* np.cos(t) * np.sin(m.radians(0))
plt.plot(xr, yr)
plt.show()
print(x)