'Polar pcolormesh shifts center when used set_ylim in matplotlib

Although I am providing a excerpt of the code I am using, but this piece contains the problem I am facing. I am trying to plot density of the particles over the disc and hence polar plot seems natural to use. So I have used following piece of code to read a density file which contains the density with rows and column representing radius and angular direction.

#! /usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from os.path import exists
from os import sys
import matplotlib as mpl
from matplotlib import rc

NUMBINS=100
rmax=20.0
dR2=rmax*rmax/NUMBINS


density = np.random.random((NUMBINS, NUMBINS))
r = np.sqrt(np.arange(0,rmax*rmax,dR2) )[:NUMBINS]
theta = np.linspace(0,2*np.pi,NUMBINS)

mpl.rcParams['legend.fontsize'] = 10
mpl.rcParams['pcolor.shading'] ='nearest'

fig = plt.figure(figsize=(5, 5))
ax1 = plt.subplot(111,projection="polar")

rad, th = np.meshgrid(r,theta)

ax1.set_yticks(np.arange(0,rmax,3))
ax1.pcolormesh(th,rad,density,cmap='Blues')
#ax1.set_ylim([rad[0,0], rad[0,NUMBINS-1]])

plt.tight_layout()
plt.show()

which gives me the following plot :

enter image description here

As you can see that the radius starts from 0 to rmax, removing the commented line

ax1.set_ylim([rad[0,0], rad[0,NUMBINS-1]])

shall not have any effect on the plot but it shifts the center of the plot :

enter image description here

I don't understand why setting ymin=0 creates this white space in the center?



Solution 1:[1]

Turns out that it is a problem with version of matplotlib. I tried a different version and the plot works as expected. Apologies for not trying it earlier.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abhishek Anand