[英]How to plot 2 maps in 1 plot using Matplotlib? (Python)
I was trying to overlay 1 map on another, but I could not.我试图将 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()
The above code, only shows last ax.imshow(i_file_data)
上面的代码,只显示了最后一个ax.imshow(i_file_data)
The idea is that I have a map1, and map2.这个想法是我有一个map1和map2。 I want to overlay map2 with alpha = 0.5
on map1, and plot it.我想用alpha = 0.5
在 map1 和 plot 上覆盖 map2。
There's an example in the matplotlib documentation similar to your case: https://matplotlib.org/stable/gallery/images_contours_and_fields/layer_images.html#sphx-glr-gallery-images-contours-and-fields-layer-images-py matplotlib 文档中有一个与您的案例类似的示例: https://matplotlib.org/stable/gallery/images_contours_and_fields/layer_images.html#sphx-glr-and-fields-layer-images-contours
If I am getting you correctly then this should work.如果我让你正确,那么这应该有效。 I assume your bottom layer has color and top layer has just boundaries.我假设你的底层有颜色,顶层只有边界。
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()
You can tweak the top layer and change the opacity accordingly.您可以调整顶层并相应地更改不透明度。 If you want your map 2 be just the outline on top of map 1 then set facecolor = "none" in the second layer如果您希望 map 2 只是 map 1 顶部的轮廓,则在第二层设置 facecolor = "none"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.