[AstroPy] mollweide projection plotting (celestial sphere in Galactic coord) ?

Guillaume Blanc blanc@apc.univ-paris7...
Thu Jun 20 06:15:27 CDT 2013


Hi,

Thanks a lot. I was able to do what I wanted using matplotlib. Here is the code, and below the corresponding figure, if someone is interested.

Guillaume Blanc

---------------
import numpy as np
import pylab as pl
import math

# the spot to plot
x = np.array([-37, 88, -137, -139, -136, -44]) # longitude
y = np.array([27, -60, -1.4, -50, -77, -46]) # latitude
lab = ['TF0.1', 'TF0.2', 'TF0.3', 'TF0.4', 'TF0.5', 'TF0.6' ]

# To plot the celestial equator in galactic coordinates
degtorad = math.pi/180.
alpha = np.arange(-180,180.,1.)
alpha *= degtorad
# From Meeus, Astronomical algorithms (with delta = 0)
x1 = np.sin(192.25*degtorad - alpha)
x2 = np.cos(192.25*degtorad - alpha)*np.sin(27.4*degtorad)
yy = np.arctan2(x1, x2)
longitude = 303*degtorad - yy 
x3 = np.cos(27.4*degtorad) * np.cos(192.25*degtorad - alpha)
latitude  = np.arcsin(x3)

# We put the angles in the right direction
for i in range(0,len(alpha)):
    if longitude[i] > 2.*math.pi:
        longitude[i] -= 2.*math.pi
    longitude[i] -= math.pi
    latitude[i] = -latitude[i]

# To avoid a line in the middle of the plot (the curve must not loop)
for i in range(0,len(longitude)-1):
    if (longitude[i] * longitude[i+1] < 0 and longitude[i] > 170*degtorad and longitude[i+1] < -170.*degtorad):
        indice = i
        break

# The array is put in increasing longitude 
longitude2 = np.zeros(len(longitude))
latitude2 = np.zeros(len(latitude))
longitude2[0:len(longitude)-1-indice] = longitude[indice+1:len(longitude)]
longitude2[len(longitude)-indice-1:len(longitude)] = longitude[0:indice+1]
latitude2[0:len(longitude)-1-indice] = latitude[indice+1:len(longitude)]
latitude2[len(longitude)-indice-1:len(longitude)] = latitude[0:indice+1]

xrad = x * degtorad
yrad = y * degtorad

fig2 = pl.figure(2)
ax1 = fig2.add_subplot(111, projection="mollweide")

ax1.scatter(xrad,yrad)
ax1.plot([-math.pi, math.pi], [0,0],'r-')
ax1.plot([0,0],[-math.pi, math.pi], 'r-')

# plot celestial equator
ax1.plot(longitude2,latitude2,'g-')

for i in range(0,6):
    ax1.text(xrad[i], yrad[i], lab[i])

pl.title("Test Fields")
pl.grid(True)

pl.show()
------------



Le 19 juin 2013 à 19:10, Kelle Cruz <kellecruz@gmail.com> a écrit :

> this is also included in one of the tutorials Adrian and I worked on:
> https://github.com/astropy/astropy-tutorials/blob/master/tutorials/Plot-Catalog/plot-catalog.py
> 
> 
> On Wed, Jun 19, 2013 at 12:21 PM, Marshall Perrin <mperrin@stsci.edu> wrote:
> On Jun 19, 2013, at 11:50 AM, Guillaume Blanc wrote:
> > I'm looking in a python library to plot a mollweide projection of the celestial sphere with some points and lines between two points... I tried using healpy, but the projplot function doesn't work well, and the plotting options look limited (well, it's not the main goal of that library, actually).
> >
> > To try to be clearer, I'd like to plot some objects in a projection of the celestial sphere in galactic coordinates with the standard mollweide projection, and plot as well some "lines" such as the celestial equator and so on...
> >
> > I'm sure something exist somewhere to do that!
> 
> 
> This can actually all be done in plain matplotlib, just by setting the 'projection' keyword when setting up the plot axes.
> 
> See http://matplotlib.org/examples/pylab_examples/geo_demo.html
> 
> 
>  - Marshall
> _______________________________________________
> AstroPy mailing list
> AstroPy@scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
> 
> 
> 
> -- 
> Kelle Cruz, PhD — http://kellecruz.com/
> 917.725.1334 — Hunter: x16486 — AMNH: x3404

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/astropy/attachments/20130620/bc6c5259/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: figure_2.png
Type: image/png
Size: 67690 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/astropy/attachments/20130620/bc6c5259/attachment-0001.png 


More information about the AstroPy mailing list