数据是天空中对象的坐标,例如,如下所示:
import pylab as plt
import numpy as np
l = np.random.uniform(-180, 180, 2000)
b = np.random.uniform(-90, 90, 2000)
Run Code Online (Sandbox Code Playgroud)
我想做一个2D直方图,以便(l, b)在Mollweide投影上使用HEALPix像素化来绘制某个点的密度与天空中坐标的映射。如何使用healpy做到这一点?
本教程:
说了如何绘制一维数组或拟合文件,但我没有找到如何使用这种像素化来绘制二维直方图。
我也找到了此功能,但无法正常工作,因此卡住了。
hp.projaxes.MollweideAxes.hist2d(l, b, bins=10)
Run Code Online (Sandbox Code Playgroud)
我可以这样在Mollweide投影中绘制这些点:
l_axis_name ='Latitude l (deg)'
b_axis_name = 'Longitude b (deg)'
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(111, projection="mollweide")
ax.grid(True)
ax.scatter(np.array(l)*np.pi/180., np.array(b)*np.pi/180.)
plt.show()
Run Code Online (Sandbox Code Playgroud)
预先非常感谢您的帮助。
lll我尝试用和bbb变量绘制散点图amplitudes带有颜色条的 mollweide 投影来绘制
如果我做
import pylab as plt
import numpy as np
lll=N.random.uniform(-180,180,10000)
bbb=N.random.uniform(-90,90,10000)
amp=N.random.uniform(0,1,10000)
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(111, projection="mollweide")
ax.scatter(N.array(lll)*N.pi/180., N.array(bbb)*N.pi/180., c=amp)
ax.grid(True)
Run Code Online (Sandbox Code Playgroud)
我得到了我想要的图,但没有颜色条。如果我添加一行ax.colorbar()或plt.colorbar()它不起作用。
在此先感谢您的帮助。
我有一个用HEALPY制作的HealPix图,如Healpy:从数据到Healpix图(像素较少,例如,nside = 2,请参见下面的代码)。
import healpy as hp
import numpy as np
import matplotlib.pyplot as plt
# Set the number of sources and the coordinates for the input
nsources = int(1.e4)
nside = 2
npix = hp.nside2npix(nside)
# Coordinates and the density field f
thetas = np.random.random(nsources) * np.pi
phis = np.random.random(nsources) * np.pi * 2.
fs = np.random.randn(nsources)
# Go from HEALPix coordinates to indices
indices = hp.ang2pix(nside, thetas, phis)
# Initate the map and fill it …Run Code Online (Sandbox Code Playgroud) 我说两种分布具有不同的价差
a=N.random.normal(0,0.5,500)
b=N.random.normal(1,3.,500)
Run Code Online (Sandbox Code Playgroud)
我想对它们进行直方图,其中最大值处于同一水平。
如果我使用density = True参数制作归一化的直方图,它将使两个直方图的面积均为1,这不会改变最大值不同的事实。
P.hist(a, histtype='step', lw=2, cumulative=True)
P.hist(b, histtype='step', color='r', lw=2, density=True)
Run Code Online (Sandbox Code Playgroud)
我想要的是制作一个以最大值“标准化”的直方图。我的意思是,当蓝色和红色直方图的最大值相同时,比较它们可能很容易。在此先感谢您的帮助。
plot ×4
python ×4
matplotlib ×3
healpy ×2
astronomy ×1
histogram ×1
histogram2d ×1
scatter-plot ×1