两个2d直方图和一个颜色条

时间:2019-03-19 14:01:55

标签: python matplotlib colorbar histogram2d

我绘制了一个2d直方图(来自ceo数据帧中的参数):

binx=np.linspace(np.min(ceo.masa_z_Rmax),np.max(ceo.masa_z_Rmax),80)
biny=np.linspace(np.min(np.log10(ceo.SFR_Rmax)),np.max(np.log10(ceo.SFR_Rmax)),80)
median, bin_edges_zm, bin_edges_sfr, c=stats.binned_statistic_2d(ceo.masa_z_Rmax, np.log10(ceo.SFR_Rmax), values=ceo.met_g_Rmax, statistic='median', bins=[binx,biny])
median=np.nan_to_num(median,copy=True)
fig, ax = plt.subplots()
hist=ax.pcolormesh(binx, biny, median.T, norm=LogNorm(), cmap='viridis')
ax.set_xlabel(r'$\rm{\log(M_\ast)}$')
ax.set_ylabel(r'$\rm{\log{SFR}}$')

然后我想用从表中获取的另一个二维直方图进行绘图:

man_mass=np.linspace(9.1,11.35,16)
man_sfr=np.linspace(-1.45,0.8,16)
man_med=np.array([[0.,0.,0.,0.,0.,0.,0.,8.56,0.,0.,0.,0.,0.,0.,0.,0.],
                 [0.,0.,0.,0.,0.,8.7,8.7,8.65,8.58,8.53,0.,0.,0.,0.,0.,0.],
                 [0.,0.,8.77,8.76,8.73,8.75,8.76,8.71,8.69,8.64,8.58,8.53,0.,0.,0.,0.],
                 [0.,8.83,8.82,8.82,8.81,8.79,8.79,8.77,8.78,8.74,8.69,8.66,8.59,0.,0.,0.],
                 [8.90,8.90,8.90,8.88,8.88,8.87,8.86,8.85,8.83,8.81,8.79,8.72,8.69,8.64,8.63,0.],
                 [8.98,8.96,8.95,8.94,8.94,8.93,8.93,8.92,8.90,8.88,8.85,8.82,8.77,8.72,8.71,0.],
                 [9.02,9.01,8.99,8.98,8.98,8.98,8.98,8.97,8.96,8.94,8.92,8.89,8.85,8.82,8.79,0.],
                 [9.05,9.04,9.03,9.02,9.02,9.02,9.01,9.01,9.01,8.99,8.97,8.96,8.92,8.88,8.86,8.84],
                 [0.0,9.06,9.05,9.04,9.04,9.03,9.03,9.03,9.03,9.03,9.02,8.99,8.98,8.94,8.90,0.0],
                 [0.0,9.08,9.07,9.05,9.05,9.05,9.05,9.05,9.05,9.05,9.04,9.04,9.01,9.0,8.97,8.93],
                 [0.0,9.09,9.07,9.06,9.06,9.06,9.06,9.06,9.06,9.06,9.06,9.05,9.04,9.03,9.0,8.98],
                 [0.0,0.0,9.09,9.07,9.06,9.07,9.06,9.06,9.06,9.06,9.07,9.07,9.06,9.05,9.04,9.02],
                 [0.0,0.0,0.0,9.09,9.08,9.08,9.07,9.07,9.07,9.07,9.07,9.07,9.06,9.07,9.06,9.04],
                 [0.0,0.0,0.0,0.0,0.0,9.09,9.07,9.07,9.07,9.07,9.07,9.06,9.07,9.07,9.07,0.0],
                 [0.0,0.0,0.0,0.0,0.0,0.0,9.09,9.08,9.08,9.07,9.07,9.07,9.07,9.08,9.05,0.0],
                 [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,9.06,9.07,9.07,9.06,9.06,0.0,0.0,0.0] ])

hist=ax.pcolormesh(man_mass, man_sfr, man_med.T, norm=LogNorm(), cmap='viridis')
fig.colorbar(hist,ax=ax)

有了这个,我在颜色条上得到了具有不同最小和最大颜色的直方图。例如,在第一个绘制的直方图中,我得到9的深蓝色正方形,而在11中得到最亮的黄色,对于过度绘制的直方图,我得到8.5的深蓝色,而得到9.1的黄色。我有两个比例尺不同的颜色条(如果我想画的话)。 我想将两个直方图都映射到一个颜色条上,这样我绘制的直方图通常会更暗,并且可以对其计数进行真正的比较。 您可以帮我修改我的代码吗?

0 个答案:

没有答案