我在下面有一个很好的hexbin图,但我想知道有没有什么方法可以让hexbin进入一个Aitoff投影显著的代码是:

import numpy as np
import math
import matplotlib.pyplot as plt
from astropy.io import ascii

filename = 'WISE_W4SNRge3_and_W4MPRO_lt_6.0_RADecl_nohdr.dat'
datafile= path+filename
data = ascii.read(datafile)
points = np.array([data['ra'], data['dec']])

color_map = plt.cm.Spectral_r
points = np.array([data['ra'], data['dec']])
xbnds = np.array([ 0.0,360.0])
ybnds = np.array([-90.0,90.0])
extent = [xbnds[0],xbnds[1],ybnds[0],ybnds[1]]

fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(111)
x, y = points
gsize = 45
image = plt.hexbin(x,y,cmap=color_map,
    gridsize=gsize,extent=extent,mincnt=1,bins='log')

counts = image.get_array()
ncnts = np.count_nonzero(np.power(10,counts))
verts = image.get_offsets()

ax.set_xlim(xbnds)
ax.set_ylim(ybnds)
plt.xlabel('R.A.')
plt.ylabel(r'Decl.')
plt.grid(True)
cb = plt.colorbar(image, spacing='uniform', extend='max')
plt.show()

我试过:
plt.subplot(111, projection="aitoff")

在执行plt.hexbin命令之前,它只给出了一个漂亮但空白的aitoff网格。
python - 将matplotlib hexbin放入Aitoff投影中-LMLPHP

最佳答案

问题是aitoff投影使用的是从-π到+π的弧度。不是从0到360度我使用Angle.wrap_at函数来实现这一点,正如this Astropy example(它基本上告诉您如何创建一个适当的Aitoff投影图)。
此外,你不能改变轴限制(这将导致一个错误),并且不应该使用extent(作为Beurnest'的答案也陈述)。
您可以按如下方式更改代码以获得所需的内容:

import numpy as np
import matplotlib.pyplot as plt
from astropy.io import ascii
from astropy.coordinates import SkyCoord
from astropy import units

filename = 'WISE_W4SNRge3_and_W4MPRO_lt_6.0_RADecl_nohdr.dat'
data = ascii.read(filename)
coords = SkyCoord(ra=data['ra'], dec=data['dec'], unit='degree')
ra = coords.ra.wrap_at(180 * units.deg).radian
dec = coords.dec.radian

color_map = plt.cm.Spectral_r
fig = plt.figure(figsize=(6, 4))
fig.add_subplot(111, projection='aitoff')
image = plt.hexbin(ra, dec, cmap=color_map,
                   gridsize=45, mincnt=1, bins='log')

plt.xlabel('R.A.')
plt.ylabel('Decl.')
plt.grid(True)
plt.colorbar(image, spacing='uniform', extend='max')
plt.show()

它给予
python - 将matplotlib hexbin放入Aitoff投影中-LMLPHP

08-25 03:31