0

I would like to make a contour plot in polar coordinates, but I am not being able to do so. I took suggestion from an accepted answer of a similar question asked here, but that results in just plotting the axes and the contour is not plotted in my case.
I am attaching the code below:

def plotcnt():
   import matplotlib.pyplot as plt
   import numpy as np
   azimuths = np.radians(np.linspace(0, 360, 360))
   zeniths = np.arange(0, 2.1,20)
   r,theta=np.meshgrid(zeniths,azimuths)

   values= r*np.log(theta+2)


   fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
   ax.contourf(theta, r, values)
   plt.show()


plotcnt()
hpaulj
  • 221,503
  • 14
  • 230
  • 353
Normie
  • 113
  • 5

1 Answers1

1

The way you're using np.arange to create the zeniths variable will give you only [0].

If you use linspace instead, it will give you some data to show.

def plotcnt():
  import matplotlib.pyplot as plt
  import numpy as np
  azimuths = np.radians(np.linspace(0, 360, 360))
  zeniths = np.linspace(0, 2.1,20)
  r,theta=np.meshgrid(zeniths,azimuths)

  values= r*np.log(theta+2)


  fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
  ax.contourf(theta, r, values)
  plt.show()

plotcnt()

Hope this helps.

Cheers!

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Pedro
  • 182
  • 5
  • 13