问题描述
我想在matplotlib极坐标图内创建一个颤动图。如下图所示(左子图),我的MWE在rmin=0
上正常工作,但对于rmin
(右子图)的其他任何值,我的MWE均未达到要求。
我还尝试计算极坐标中的端点,并将quiver()
与angles='xy'
参数一起使用,但这由于某种原因根本不起作用,我也不明白为什么。但是,如果我将折线图与计算出的端点结合使用,它将按预期工作。
与线图相比,我更喜欢使用颤动图,原因是我想为该图设置动画并动态添加/删除点。对于颤动图,我可以简单地通过设置偏移量和U
和V
值来实现;对于折线图,我必须添加/删除折线图,并与set_data()
。
from matplotlib import pyplot as plt
import numpy as np
if __name__ == '__main__':
N = 11 # number of samples
x = np.linspace(0,10,N)
y = np.sin(x)
theta,r = np.arctan2(y,x),np.hypot(x,y) # convert to polar
gradient = [np.ones(N),np.cos(x)]
gradient = gradient / np.hypot(gradient[0],gradient[1]) # normalize
endpoints_x = x + gradient[0]
endpoints_y = y + gradient[1]
# convert cartesian endpoints to polar
endpoints_theta,endpoints_r = np.arctan2(endpoints_y,endpoints_x),\
np.hypot(endpoints_x,endpoints_y)
fig,axes = plt.subplots(1,2,figsize=(10,8),subplot_kw=dict(polar=True))
for i in range(2):
axes[i].scatter(theta,r,marker='o')
axes[i].plot(np.stack((theta,endpoints_theta)),np.stack((r,endpoints_r)),'r')
# works only for rmin=0
axes[i].quiver(theta,gradient[0],gradient[1],angles='uv')
# does not work at all
#axes[i].quiver(theta,endpoints_theta,endpoints_r,angles='xy')
axes[i].set_thetamin(-90)
axes[i].set_thetamax(90)
axes[1].set_rmin(2)
fig.tight_layout()
plt.show()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)