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

后端 未结 2 1895
感动是毒
感动是毒 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

    0 讨论(0)
  • 2020-11-30 03:10

    the shape of x, y and values must be the same. Your data shape is:

    >>> x.shape, y.shape, values.shape
    ((36, 7), (36, 7), (7, 36))
    

    so change contour(x, y, values) to contour(x, y, values.T).

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