Polar contour plot in matplotlib - best (modern) way to do it?

后端 未结 2 1894
感动是毒
感动是毒 2020-11-30 02:52

Update: I\'ve done a full write-up of the way I found to do this on my blog at http://blog.rtwilson.com/producing-polar-contour-plots-with-matplotlib/ - you

2条回答
  •  情歌与酒
    2020-11-30 03:06

    You should just be able to use ax.contour or ax.contourf with polar plots just as you normally would... You have a few bugs in your code, though. You convert things to radians, but then use the values in degrees when you plot. Also, you're passing in r, theta to contour when it expects theta, r.

    As a quick example:

    import numpy as np
    import matplotlib.pyplot as plt
    
    #-- Generate Data -----------------------------------------
    # Using linspace so that the endpoint of 360 is included...
    azimuths = np.radians(np.linspace(0, 360, 20))
    zeniths = np.arange(0, 70, 10)
    
    r, theta = np.meshgrid(zeniths, azimuths)
    values = np.random.random((azimuths.size, zeniths.size))
    
    #-- Plot... ------------------------------------------------
    fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
    ax.contourf(theta, r, values)
    
    plt.show()
    

    enter image description here

提交回复
热议问题