如何在Mollweide视图(Python)中绘制背景图像?

2024-04-29 11:31:48 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

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


Tags: 图像视图png图表绘制plt天空背景
1条回答
网友
1楼 · 发布于 2024-04-29 11:31:48

感谢用户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()

相关问题 更多 >