【问题标题】:Astropy matplotlib and plot galactic coordinatesAstropy matplotlib 和绘制银河坐标
【发布时间】:2015-10-13 14:53:18
【问题描述】:

我正在尝试使用 python 绘制银河坐标图。假设我有这些数据:

data = [(0.261, -7.123, 13.03, 'Unidentified'), (-0.326, 77, 13.03, '星系')]

每个元组的形式为(ra、dec、flux、type)。

我被要求使用astropy + matplotlib,所以:

c = SkyCoord(ra = ra*u.degree, dec = dec*u.degree)
galactic = c.galactic

这是我的问题出现的地方,我正在使用此代码:

from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# lon_0 is central longitude of projection.
# resolution = 'c' means use crude resolution coastlines.
m = Basemap(projection='hammer',lon_0=0,resolution='c')
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,120.,30.))
m.drawmeridians(np.arange(0.,420.,60.))
m.drawmapboundary(fill_color='aqua')
plt.title("Hammer Projection")
plt.show()

但是我无法在银河坐标系中绘制数据,我也不知道为什么。我还需要每个点根据类型具有不同的颜色,并且根据通量的值具有不同的大小。我需要实现这样的目标(我对python有点陌生,而且我从未使用过astropy,我还没有找到好的例子):

希望有人能提供帮助。

【问题讨论】:

  • 您能否澄清一下“我无法在银河坐标系中绘制数据,我也不知道为什么?”你试过什么?错误信息是什么,或者这些点没有显示出来?

标签: python matplotlib plot astropy


【解决方案1】:

查看http://www.astropy.org/astropy-tutorials/plot-catalog.html 底部的示例。我在绘制银河坐标时遇到的一个常见问题是你想要从 -180 到 +180 绘制,但默认是从 0 到 360 的坐标。你可以使用wrap_at 更改它,例如:

plot(galactic.l.wrap_at(180*u.deg), galactic.b.wrap_at(180*u.deg))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 2015-01-21
    • 1970-01-01
    • 2015-03-21
    相关资源
    最近更新 更多