在 matplotlib 中使用 set_ylim 时,Polar pcolormesh 会移动中心

Polar pcolormesh shifts center when used set_ylim in matplotlib

虽然我提供了我正在使用的代码的摘录,但这篇文章包含了我面临的问题。我正在尝试绘制圆盘上粒子的密度,因此使用极坐标图似乎很自然。所以我使用下面的代码来读取一个密度文件,其中包含密度的行和列代表半径和 angular 方向。

#! /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()

这给了我以下情节:

可以看到半径从0开始到rmax,去掉注释行

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

不会对情节有任何影响,但会改变情节的中心:

我不明白为什么设置 ymin=0 会在中间创建这个白色 space?

原来是matplotlib版本问题。我尝试了不同的版本,情节按预期进行。抱歉没有早点尝试。