如何在极坐标中绘制箭袋图
问题描述:
如何在极坐标中绘制箭袋图?我有关于r和theta的数据.我尝试过:
How do I make a quiver plot in polar coordinates? I have data in terms of r and theta. I've tried:
import numpy as np
radii = np.linspace(0.5,1,10)
thetas = np.linspace(0,2*np.pi,20)
theta, r = np.meshgrid(thetas, radii)
f = plt.figure()
ax = f.add_subplot(111, polar=True)
ax.quiver(theta, r, dr, dt)
其中dr和dt是r和theta方向上的数据向量.
where dr and dt are vectors of data in the r and theta directions.
答
看起来 quiver 不会为你做转换.您需要手动进行 (r,t) -> (x,y) 转换:
It looks like quiver does not do the conversion for you. You need to do the (r,t) -> (x,y) conversion by hand:
radii = np.linspace(0.5,1,10)
thetas = np.linspace(0,2*np.pi,20)
theta, r = np.meshgrid(thetas, radii)
dr = 1
dt = 1
f = plt.figure()
ax = f.add_subplot(111, polar=True)
ax.quiver(theta, r, dr * cos(theta) - dt * sin (theta), dr * sin(theta) + dt * cos(theta))