繁体   English   中英

如何使用 Matplotlib 在 1 个 plot 中进行 plot 2 个映射? (Python)

[英]How to plot 2 maps in 1 plot using Matplotlib? (Python)

我试图将 1 map 覆盖在另一个上,但我不能。

input_file = "slicedSmoothedStokesPlanck/Smoothed_Sliced_PSI_MAP.fits"
i_file = "slicedSmoothedStokesPlanck/Smoothed_Sliced_I_MAP.fits"
pl_b = fits.getdata(input_file, ext=0)
i_file_data = fits.getdata(i_file, ext=0)

fig = plt.figure()
ax = fig.add_subplot(111) #, projection=wcs
im = ax.imshow(texture, alpha=0.5) #, cmap='RdYlBu_r'
ax.imshow(i_file_data)
plt.title("TEST")
plt.show()

上面的代码,只显示了最后一个ax.imshow(i_file_data)

这个想法是我有一个map1和map2。 我想用alpha = 0.5在 map1 和 plot 上覆盖 map2。

如果我让你正确,那么这应该有效。 我假设你的底层有颜色,顶层只有边界。

fig, ax = plt.subplots(1,1, figsize(8, 8))
pl_b.plot(ax = ax, cmap = "RdYlBu_r", edgecolor = "black", lw = 0.1) #, this is your map 1
i_file_data.plot(ax = ax, facecolor = "none", edgecolor = "black", lw = 0.1, alpha = 0.5) #, this is your map 2
plt.title("TEST")
plt.show()

您可以调整顶层并相应地更改不透明度。 如果您希望 map 2 只是 map 1 顶部的轮廓,则在第二层设置 facecolor = "none"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM