Polar heatmaps in python

前端 未结 1 1539
陌清茗
陌清茗 2020-12-17 00:55

I want to plot a paraboloid f(r) = r**2 as a 2D polar heatmap. The output I expect is

The code that I have written is

from pylab import*
from mpl_         


        
1条回答
  •  攒了一身酷
    2020-12-17 01:06

    I think you inadvertently mixed up radius, zenith and azimuth :)

    This plots what I think you want:

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    
    fig = plt.figure()
    ax = Axes3D(fig)
    
    rad = np.linspace(0, 5, 100)
    azm = np.linspace(0, 2 * np.pi, 100)
    r, th = np.meshgrid(rad, azm)
    z = (r ** 2.0) / 4.0
    
    plt.subplot(projection="polar")
    
    plt.pcolormesh(th, r, z)
    #plt.pcolormesh(th, z, r)
    
    plt.plot(azm, r, color='k', ls='none') 
    plt.grid()
    
    plt.show()
    

    If you want ray grid lines, you can add them every Theta as follows:

    plt.thetagrids([theta * 15 for theta in range(360//15)])
    

    and more radial grids like this:

    plt.rgrids([.3 * _ for _ in range(1, 17)])
    

    PS: numpy and pyplot will keep your namespace tidy...

    0 讨论(0)
提交回复
热议问题