python - 从所有数组值创建椭圆图
问题描述
我想从代码中给出的半主要和半次要数组对中创建椭圆图,如 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
解决方案
如果我正确理解您的问题,您将创建半长轴和半短轴对的数组,并且您想为每一对绘制轮廓。
在您的代码中,当您可以简单地使用索引来遍历所有元素时,为什么只使用 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)
推荐阅读
- javascript - Node.js 项目中未定义 API 密钥 Mailgun
- objective-c - 如果应用程序删除然后重新安装,我如何获取电子邮件地址和姓名?
- c++ - 如何在 C++14 中定义下面描述的概念?
- laravel - 当我尝试安装 npm install gulp -D 这些错误显示
- c# - 挣扎使用 CefSharp
- database - NCBI BLAST,NR 数据库
- r - 使用 'by()' 描述性统计分组计算
- python - Python 3:我有问题:ValueError:没有足够的值在一个非常简单的脚本中解包(预期为 2,得到 0):
- xamarin - 错误:操作无法完成。(com.google.fcm 错误 501)
- r - 在运行多个需要访问集群的 R 程序(接近 20 个)时设置 H2O 集群