Note that there are some explanatory texts on larger screens.

plurals
  1. POPolar contour plot in matplotlib - best (modern) way to do it?
    primarykey
    data
    text
    <p><strong>Update:</strong> I've done a full write-up of the way I found to do this on my blog at <a href="http://blog.rtwilson.com/producing-polar-contour-plots-with-matplotlib/" rel="noreferrer">http://blog.rtwilson.com/producing-polar-contour-plots-with-matplotlib/</a> - you may want to check there first.</p> <p>I'm trying to plot a polar contour plot in matplotlib. I've found various resources on the internet, (a) I can't seem to get my code to work and (b) many of the resources appear rather old, and I'm wondering if there is a better way now. For example, <a href="http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg01953.html" rel="noreferrer">http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg01953.html</a> suggests that something may be done to improve things soon, and that was in 2006!</p> <p>I'd love to be able to plot proper polar contour plots - like pcolor lets you do for its type of plot (see commented out section below), but I can't seem to find any way to do that, so I'm converting to cartesian co-ordinates first.</p> <p>Anyway, I have the code that follows:</p> <pre><code>from pylab import * import numpy as np azimuths = np.arange(0, 360, 10) zeniths = np.arange(0, 70, 10) values = [] for azimuth in azimuths: for zenith in zeniths: print "%i %i" % (azimuth, zenith) # Run some sort of model and get some output # We'll just use rand for this example values.append(rand()) theta = np.radians(azimuths) values = np.array(values) values = values.reshape(len(zeniths), len(azimuths)) # This (from http://old.nabble.com/2D-polar-surface-plot-td28896848.html) # works fine ############## # Create a polar axes # ax = subplot(111, projection='polar') # pcolor plot onto it # c = ax.pcolor(theta, zeniths, values) # show() r, t = np.meshgrid(zeniths, azimuths) x = r*np.cos(t) y = r*np.sin(t) contour(x, y, values) </code></pre> <p>When I run that I get an error <code>TypeError: Inputs x and y must be 1D or 2D.</code>. I'm not sure why I get this, as both x and y are 2D. Am I doing something wrong?</p> <p>Also, it seems rather clunky to be putting my values returned from my model into a list and then reshaping it. Is there a better way to do this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload