如何用Python将Blackhawk黑洞辐射模拟数据绘制成散点图?
问题:Blackhawk黑洞辐射数据散点图一维分布异常
在Windows的WSL环境下,使用Blackhawk模拟软件处理黑洞的初级和次级光子辐射数据,基于GitHub项目nuHawkHunter的基础架构,结合Matplotlib与Jupyter编写代码。目前可将数据拟合成最佳拟合线,但无法直接从数据表格生成正常散点图;当前绘制的散点图仅沿X轴呈一维分布,无法呈现目标线图的曲线形态。
相关代码
from Source.constants import * # PBH masses Mpbhs = [3.e12, 3.e15] cols = ["r", "b", "g", "m", "y"] # 1 for plotting only nu_e, 0 for the sum of the three flavours only_nue = 1 for mm, Mpbh in enumerate(Mpbhs): # Data folder folder = folder_blackhawk + "{:.1e}".format(Mpbh) + "/" data_primary = np.genfromtxt(folder+"instantaneous_primary_spectra.txt",skip_header = 2) data_secondary = np.genfromtxt(folder+"instantaneous_secondary_spectra.txt",skip_header = 2) if only_nue: # Plot only photons tot_sec = data_secondary[:,1] tot_prim = data_primary[:,2]/3. else: # Plot sum of three neutrinos tot_sec = 0. # Sum over three neutrino species for i in [3,4,5]: tot_sec += data_secondary[:,i] tot_prim = data_primary[:,6] Esec = data_secondary[:,0]*1.e3 # in MeV Eprim = data_primary[:,0]*1.e3 intsec = interp1d(Esec, tot_sec/1.e3) # in MeV intprim = interp1d(Eprim, tot_prim/1.e3) # in MeV #plt.loglog(Esec,intprim(Esec),linestyle=":",linewidth = 2, color=cols[mm]) #plt.loglog(Esec,intsec(Esec)-intprim(Esec), linestyle="--",linewidth = 2, color=cols[mm]) #plt.loglog(Esec,intsec(Esec), linestyle="-",linewidth = 2, color=cols[mm]) plt.scatter(Eprim, intprim(Eprim), marker='o', color=cols[mm]) # Figure legend customlegend = [] for n, Mpbh in enumerate(Mpbhs): customlegend.append( Line2D([0], [0], color=cols[n], lw=4, label = r"$M_{{\rm PBH}}=$"+scinot(Mpbh)+" g")) #customlegend.append( Line2D([0], [0], color="black", linestyle=":", label="Primary")) #customlegend.append( Line2D([0], [0], color="black", linestyle="--", label="Secondary")) #customlegend.append( Line2D([0], [0], color="black", linestyle="-", label="Total")) plt.ylim(1.e12,1.e21) plt.xlim(1.e0,1.e3) plt.xlabel(r'$E_\nu{\rm \,\, [MeV]}$') plt.ylabel(r'$\frac{d^2N_\nu}{dE_\nu dt} \,\, [{\rm MeV}^{-1}{\rm s}^{-1}]$') plt.tick_params(axis='both', which='both', top=True, right=True, direction="in") plt.grid() plt.legend(handles=customlegend) plt.savefig("figures/photon_spectra_blackhawk.png", bbox_inches='tight', dpi=300) plt.show()
问题细节
当前生成的散点图所有数据点仅沿X轴分布,无法展现数据随能量变化的趋势;目标是生成类似连续曲线的分布,呈现不同PBH质量下的辐射谱特征。
内容的提问来源于stack exchange,提问作者John Carlini
相关产品推荐
相关产品推荐

