如何解决绘制天文散点图 - 均值与经度银河系
我想在healpix文件中创建一个以X轴为经度坐标的散点图 https://wwwmpa.mpa-garching.mpg.de/~ensslin/research/data/faraday2020.html(Healpix)
和 Y 轴作为 hdf5 文件中的平均值 https://wwwmpa.mpa-garching.mpg.de/~ensslin/research/data/faraday2020.html(法拉第天空 2020)
到目前为止的代码:
from astropy.io import fits #libraries
from astropy import units as u
from astropy.coordinates import galactic
import matplotlib.pyplot as plt
import h5py
from astropy_healpix import HEALPix
import numpy as np
filename='pixel_coords_map_ring_galactic_res9.fits' #healpix
hdulist=fits.open(filename)
nside = hdulist[1].header['NSIDE']
order = hdulist[1].header['ORDERING']
hp = HEALPix(nside=nside,order=order,frame=galactic())
print(hdulist[1].header)
print(nside)
print(order)
ggl = hdulist[1].data['LONGITUDE'] #storing coordinate values in ggl and ggb
ggb = hdulist[1].data['LATITUDE']
print(ggl)
gl = ggl * u.degree #convering to galactic coordinates
gb = ggb * u.degree
print(gl)
c = galactic(l=gl,b=gb)
l_rad = c.l.wrap_at(180 * u.deg).radian #X Axis
b_rad = c.b.radian
with h5py.File('faraday2020.hdf5','r') as hdf: #importing raw data from hdf5 file
print(hdf.keys())
faraday_sky_mean = hdf['faraday_sky_mean'][:] #Y Axis
faraday_sky_std = hdf['faraday_sky_std'][:]
我完全不知道如何绘制二维方形散点图,因为经度和均值采用不同的格式。另外,我需要在银河坐标中的经度。请帮忙。
解决方法
我认为你很接近。恕我直言,这个散点图比绘制两个天空图坐标(projection="aitoff"
)更容易。该过程类似于我在您之前的问题中发布的答案:Plot mean and standard dev values on skyplot using astropy from hdf5 file。您只需要对函数参数稍加修改即可。
我修改了您的代码以创建二维散点图。以下是差异的简要总结:
- 更改了
from astropy.coordinates import SkyCoord
(而不是HEALPix
) - 更改了 matplot 类型(删除
projection=
) - 在散点图上将 y 变量从
b_rad
更改为faraday_sky_mean
。 - 从
c=faraday_sky_mean
中删除了plt.scatter()
,因此数据点没有颜色编码。
见下面的代码。
from astropy import units as u
from astropy.coordinates import SkyCoord
import matplotlib.pyplot as plt
import h5py
#from astropy_healpix import HEALPix
import numpy as np
fits_file = 'pixel_coords_map_ring_galactic_res9.fits' #healpix
faraday_file = 'faraday2020.hdf5'
with fits.open(fits_file) as hdulist:
nside = hdulist[1].header['NSIDE']
order = hdulist[1].header['ORDERING']
#hp = HEALPix(nside=nside,order=order,frame=Galactic())
#print(hdulist[1].header)
#print(nside)
#print(order)
ggl = hdulist[1].data['LONGITUDE'] #storing coordinate values in ggl and ggb
ggb = hdulist[1].data['LATITUDE']
#print(ggl)
gl = ggl * u.degree #convering to galactic coordinates
gb = ggb * u.degree
#print(gl)
#c = Galactic(l=gl,b=gb)
c = SkyCoord(l=gl,b=gb,frame='galactic',unit = (u.deg,u.deg))
l_rad = c.l.wrap_at(180 * u.deg).radian #X Axis
b_rad = c.b.radian
print(len(l_rad))
with h5py.File(faraday_file,'r') as hdf: #importing raw data from hdf5 file
#print(hdf.keys())
faraday_sky_mean = hdf['faraday_sky_mean'][:] #Y Axis
print(len(faraday_sky_mean))
faraday_sky_std = hdf['faraday_sky_std'][:]
plt.figure(figsize=(8,4.2))
plt.subplot(111)
plt.title("Mean",y=1.08,fontsize=20)
plt.grid(True)
P2 = plt.scatter(l_rad,faraday_sky_mean,s=20,cmap='hsv')
plt.subplots_adjust(top=0.95,bottom=0.0)
plt.xlabel('l (deg)',fontsize=20)
plt.ylabel('Mean',fontsize=20)
plt.subplots_adjust(top=0.95,bottom=0.0)
plt.show()
print('DONE')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。