极坐标图中的matplotlib颤动

问题描述

我想在matplotlib极坐标图内创建一个颤动图。如下图所示(左子图),我的MWE在rmin=0上正常工作,但对于rmin(右子图)的其他任何值,我的MWE均未达到要求。

我还尝试计算极坐标中的端点,并将quiver()angles='xy'参数一起使用,但这由于某种原因根本不起作用,我也不明白为什么。但是,如果我将折线图与计算出的端点结合使用,它将按预期工作。

与线图相比,我更喜欢使用颤动图,原因是我想为该图设置动画并动态添加/删除点。对于颤动图,我可以简单地通过设置偏移量和UV值来实现;对于折线图,我必须添加/删除折线图,并与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()

quiver plot in polar plot

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...