首页 > 解决方案 > 如何在 Mollweide 视图(Python)中绘制背景图像?

问题描述

我正在使用天空坐标进行天文数据分析。如何将图像放置为 Mollweide 视图图的背景?我尝试的是正常绘制图表并添加:

imag = mpimg.imread('gamma_ray_Fermi.png')
plt.imshow(imag)

但它只是返回一个变形图,而不是通常的背景图。

标签: pythonmatplotlibplotastronomy

解决方案


感谢用户 ImportanceOfBeingErnest 的评论,了解它是如何工作的。这是有效的代码:

import numpy as np
import matplotlib.pyplot as plt

data = plt.imread("yourimagehere.png")

fig = plt.figure()
#create axes in the background to show cartesian image
ax0 = fig.add_subplot(111)
ax0.imshow(data)
ax0.axis("off")

# create polar axes in the foreground and remove its background
# to see through
ax = fig.add_subplot(111, projection="mollweide", label="polar") 
#you can change to other projections like "hammer"
ax.set_facecolor("None")

plt.show()

推荐阅读