0

I'm plotting some hydrodynamical simulation data run in spherical coordinates and sometimes prefer to use contourf over pcolormesh because it looks nice and smooth instead of pixelated. However, I notice that contourf always extends my data to r=0 in a polar plot, yet my data never includes r=0. I have reproduced this issue with the simple example below:

from pylab import *  

fig = figure(figsize=(6, 6)) 
ax = fig.add_subplot(111,projection='polar')

# generate some data
Nt,Nr = 150,150
r_axis = np.linspace(0.5,1.,Nr)
t_axis = np.linspace(0.,0.5*np.pi,Nt)
r_grid, t_grid = np.meshgrid(r_axis,t_axis)

data = np.zeros((Nt,Nr))
sin_theta = np.sin(t_axis)
for i in range(Nr):
    data[:,i] = sin_theta

if 1: # polar plot using contourf - plots incorrectly from r = 0
    scale = np.linspace(0.,1.,100)
    polar = ax.contourf(t_grid,r_grid,data,scale,cmap='Spectral')
else: # correctly plots the data
    polar = ax.pcolormesh(t_grid,r_grid,data,cmap='Spectral')
show()

Is there a quick fix? Thanks

trw
  • 3
  • 1

1 Answers1

0

One can set the axes limits. The radial scale is set as y, therefore

ax.set_ylim(0,1) 

will set the origin to 0.

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712