首页 > 解决方案 > 从所有数组值创建椭圆图

问题描述

我想从代码中给出的半主要和半次要数组对中创建椭圆图,如 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

标签: pythonnumpymatplotlibiteration

解决方案


如果我正确理解您的问题,您将创建半长轴和半短轴对的数组,并且您想为每一对绘制轮廓。

在您的代码中,当您可以简单地使用索引来遍历所有元素时,为什么只使用 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)

推荐阅读