繁体   English   中英

如何从此函数生成散射极坐标图,使用列作为我的绘图坐标?

[英]How do I generate a scatter polar plot, from this function, Using the columns as my plot coordinates?

我想根据这些角度的正弦值(从相同函数,第二列生成)创建我的角度的极坐标图(从函数,第一列生成)。 很少有试验方法产生了积分但没有积分。

 def GenerateTrigonometryTable(x):
A = np.arange (0,360,x) 
B = np.sin(A*np.pi/180)  
C = np.cos(A*np.pi/180)
D = []
F = []
G = []
for i in range (len(A)): 
    D.append(A[i])
for i in range (len(B)): 
    F.append(B[i])
for i in range (len(C)): 
    G.append(C[i])
table =([D],[F],[G]) 
table = np.dstack((table)) 
return (table) 

 Theta = (GenerateTrigonometryTable(5)[:,:,0])
 STheta = (GenerateTrigonometryTable(5)[:,:,1])
 ax1 = plt.subplot(111, projection='polar')
 ax1.plot(Theta, STheta)

 plt.show()
 plt.draw()

我希望在极坐标图上有一个典型的正弦模式,但我希望从我的函数中得出它。

让我们首先简化您的功能:

def GenerateTrigonometryTable(x):
    A = np.arange (0,360,x) 
    B = np.sin(A*np.pi/180)  
    C = np.cos(A*np.pi/180)
    return np.dstack(([A],[B],[C])) 

t = GenerateTrigonometryTable(5)
print(t.shape)

输出是一个形状为3D的阵列(1,72,3) 为了绘制它,您需要将切片展平。

Theta = (GenerateTrigonometryTable(5)[:,:,0])
STheta = (GenerateTrigonometryTable(5)[:,:,1])
ax1 = plt.subplot(111, projection='polar')
ax1.plot(Theta.flatten(), STheta.flatten())

plt.show()

在此输入图像描述

现在,这可能是也可能不是你所追求的,所以让我建议修改功能如下

  • 使用辐射而不是度
  • 将数组堆叠为列以获取2D数组
  • 包括阵列中的2 pi

码:

import numpy as np
import matplotlib.pyplot as plt

def GenerateTrigonometryTable(x):
    A = np.deg2rad(np.arange(0,360+0.5,x))
    B = np.sin(A)  
    C = np.cos(A)
    return np.column_stack((A,B,C)) 

t = GenerateTrigonometryTable(5)
print(t.shape)

theta = (GenerateTrigonometryTable(5)[:,0])
stheta = (GenerateTrigonometryTable(5)[:,1])
ax1 = plt.subplot(111, projection='polar')
ax1.plot(theta, stheta)

plt.show()

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM