【问题标题】:How could I plot circular histogram like this in matplotlib?如何在 matplotlib 中绘制这样的圆形直方图?
【发布时间】:2022-01-21 07:51:57
【问题描述】:

我需要在 matplotlib 中绘制圆形直方图! 它们应该看起来像

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np; np.random.seed(1)
    
    r = np.ones(100)*0.9
    phi = np.random.rand(100)*2.*np.pi
    
    hist, xedges, yedges = np.histogram2d(r, phi, bins=25, range=[[0, 1.2], [0,2*np.pi*26./25]])
    R,Phi = np.meshgrid(xedges[:-1], yedges[:-1])
    X = R*np.cos(Phi)
    Y = -R*np.sin(Phi) 
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    X[(R < 0.75) | (R > 1)] = np.nan
    ax.plot_surface(X,Y, hist.T, alpha=0.2)
    ax.plot_wireframe(X,Y, hist.T)
    plt.show()
    

    输出:

    【讨论】:

    • 注释代码以描述主要步骤可能对提问者有用;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2014-03-07
    • 1970-01-01
    相关资源
    最近更新 更多