Issue when using projection "TypeError: Changing axes limits of a geographic projection is not supported."

Issue when using projection "TypeError: Changing axes limits of a geographic projection is not supported."

我正在尝试使用 projection aitoff 绘制两个坐标数组(大约 480 万个元素),例如:

fig = plt.figure(figsize=(12,10))
ax = fig.add_subplot(111, projection="aitoff")
ax.grid(alpha=0.3)
ax.hist2d(ra, dec, bins = 100) 

但是我得到以下错误:

TypeError: Changing axes limits of a geographic projection is not supported.  Please consider using Cartopy.

坐标(radec)已经是弧度了。 我还尝试使用以下 hexbin:

ax.hexbin(ra, dec, bins = 100)

这行得通。你能帮忙吗?

我找到了答案。这是一个使用度数而不是弧度手动投影所有点的函数:

degrad = np.pi/180.

def project(li,bi,lz):
   sa = li-lz
   if len(sa) == 1:
      sa = np.zeros(1)+sa
   
   x180 = np.where(sa >= 180.0)
   
   sa = sa
   sa[x180] = sa[x180]-360.0*abs(np.cos(lz*degrad/2.))#uncomment b=0
   
   alpha2 = sa*degrad/2.
   delta = bi*degrad
   
   r2 = np.sqrt(2.)
   f = 2.*r2/np.pi
   
   cdec = np.cos(delta)
   denom = np.sqrt(1.+cdec*np.cos(alpha2))
   
   xx = cdec*np.sin(alpha2)*2.*r2/denom
   yy = np.sin(delta)*r2/denom
   
   xx = xx*(1./degrad)/f
   yy = yy*(1./degrad)/f
   return xx,yy

然后

ra, dec = project(np.array(ra), np.array(dec), 180)    
binner1 = np.linspace(-180, 180, 1000)
binner2 = np.linspace(-90, 90, 1000)
img, xbins,ybins = np.histogram2d(ra, dec, bins=(binner1,binner2))
fig, ax = plt.subplots(figsize=(10.,6.))
plot = ax.imshow(img.T, origin='lower', extent=[xbins[0],xbins[-1],ybins[0],ybins[-1]],
                 cmap=plt.cm.viridis, interpolation='gaussian', aspect='auto',
                 vmax=40,vmin=0)