Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:55:06+00:00 2026-05-29T05:55:06+00:00

Update: I’ve done a full write-up of the way I found to do this

  • 0

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 may want to check there first.

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, http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg01953.html suggests that something may be done to improve things soon, and that was in 2006!

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.

Anyway, I have the code that follows:

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)

When I run that I get an error TypeError: Inputs x and y must be 1D or 2D.. I’m not sure why I get this, as both x and y are 2D. Am I doing something wrong?

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:55:07+00:00Added an answer on May 29, 2026 at 5:55 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: I found that the easiest way is to use AQuery . I need
UPDATE : The full site code is here - https://github.com/eWizardII/PeerInstruction I have the following
Update: This does work, I was being stupid :( i have the following extension
Update: This is, as I was told, no principle Python related problem, but seems
Update Putting this at the top because it is crazy :) So some users
UPDATE This is an old question for an old version of Xcode. It turned
Update 2018 TL;DR; LaTEX for WPF https://github.com/ForNeVeR/wpf-math Original question I need to have a
UPDATE: I made a mistake in my debugging - this question is not relavent
UPDATE : A commenter told me to change some codes, this is the new
UPDATE: I added this to my unload function: $(window).resize(function(){ var pageheight = $(window).height(); $('section').css('height',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.