![](/img/trans.png)
[英]How can I draw a scatter plot with contour density lines in polar coordinates using Matplotlib?
[英]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()
现在,这可能是也可能不是你所追求的,所以让我建议修改功能如下
码:
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.