<p>Ok, community helped me to figure out that I faced the “mapping from the inside” issue (explained <a href="https://astronomy.stackexchange.com/questions/16339/what-is-the-galactic-latitude-and-galactic-longitude-how-is-different-from-the">here</a>). I'll use this answer to show my final code.</p>
<pre><code>import numpy as np
from astropy.coordinates import SkyCoord
import astropy.units as u
import matplotlib.pyplot as plt
import seaborn as sns

sns.set()

def eq2gal(ra, dec):
    
    '''
    Transforms equatorial coordinates to galactic ones.
    Then prepares them for matplotlib aitoff projection. 
    '''
    
    eq = SkyCoord(ra, dec, unit=u.deg)
    gal = eq.galactic

    # Minus appears because of “mapping from the inside” issue
    l_gal, b_gal = -gal.l.wrap_at('180d').radian, gal.b.radian
    
    return l_gal, b_gal

def ecl2gal(lon_ecl, lat_ecl):
    
    '''
    Transforms ecliptic coordinates to galactic ones.
    Then prepares them for matplotlib aitoff projection.
    '''
    
    ecl = SkyCoord(lon_ecl, lat_ecl, unit=u.deg, frame='barycentricmeanecliptic')
    gal = ecl.transform_to('galactic')

    # Minus appears because of “mapping from the inside” issue
    l_gal, b_gal = -gal.l.wrap_at('180d').radian, gal.b.radian
    
    return l_gal, b_gal

# Equatorial plane
ra_all = np.linspace(-180, 180, 100)
dec_0 = np.zeros(100)

l_eq_gal, b_eq_gal = eq2gal(ra_all, dec_0)

# Ecliptic plane
lon_ecl = np.linspace(0, 360, 100)
lat_ecl = np.zeros(100)

l_ecl_gal, b_ecl_gal = ecl2gal(lon_ecl, lat_ecl)


plt.figure(figsize=(14,7))
plt.subplot(111, projection='aitoff')

plt.scatter(l_eq_gal, b_eq_gal, s=4, marker='v', label='Celestial Equator')
plt.scatter(l_ecl_gal, b_ecl_gal, s=4, marker='^', label='Eclptic')

# Essential thing is to rename RA axis ticks to transform them to conventional format
plt.xticks(ticks=np.radians([-150, -120, -90, -60, -30, 0, \
                             30, 60, 90, 120, 150]),
           labels=['150°', '120°', '90°', '60°', '30°', '0°', \
                   '330°', '300°', '270°', '240°', '210°'])


plt.grid(True)
plt.legend(fontsize=16, loc='lower center')

plt.title('Galactic', fontsize='16')

plt.show()
</code></pre>
<p><a href="https://i.sstatic.net/jKCaq.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jKCaq.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2020-10-21T09:13:00.780Z
2021-01-09T07:45:49.947Z
2021-01-09T07:45:49.947Z
Michael Belvedersky
<p>I'm trying to plot celestial equator in galactic coordinates. Here is my code (based on <a href="https://astronomy.stackexchange.com/a/32615/36518">this</a> answer):</p>
<pre><code>import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import numpy as np

from astropy.coordinates import SkyCoord
from astropy import units as u

ra_all = np.linspace(-180, 180, 100)
dec_0 = np.zeros(100)

# Transform equatorial coordinates to galactic
eq = SkyCoord(ra_all, dec_0, unit=u.deg)
gal = eq.galactic
l_plot, b_plot = gal.l.wrap_at('180d').radian, gal.b.radian


lon = np.linspace(0, 360, 100)
lat = np.zeros(100)

# Transform ecliptic coordinates to galactic
ecl = SkyCoord(lon, lat, unit=u.deg, frame='barycentricmeanecliptic')
ecl_gal = ecl.transform_to('galactic')
l_ecl_gal, b_ecl_gal = ecl_gal.l.wrap_at('180d').radian, ecl_gal.b.radian


plt.figure(figsize=(14,7))
plt.subplot(111, projection='aitoff')

plt.scatter(l_plot, b_plot, s=5, label='Celestial Equator')
plt.scatter(l_ecl_gal, b_ecl_gal, s=5, label='Eclptic')


plt.grid(True)
plt.legend(fontsize=16)

plt.show()
</code></pre>
<p><a href="https://i.sstatic.net/UbV4n.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UbV4n.png" alt="enter image description here" /></a></p>
<p>However, the map I drew seems to be flipped left to right compared to the one bellow (taken from <a href="https://svs.gsfc.nasa.gov/11342" rel="nofollow noreferrer">here</a>)</p>
<p><a href="https://i.sstatic.net/Iehnf.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Iehnf.jpg" alt="enter image description here" /></a></p>
<hr />
<p><strong>Question 1:</strong> Why does the result of my implementation appear to be the reverse of the other image? Do I have something wrong, or is this simply an issue of mapping the surface from the inside versus from the outside?</p>
<p><strong>Question 2:</strong> What is the best way to change my code to make it draw galactic map in a conventional format?</p>

CC BY-SA 4.0
2020-10-19T01:56:55.783Z
I adjusted your wording a little bit to better fit the site. I think this is an interesting question and might have an interesting answer!
uhoh
CC BY-SA 4.0
2020-10-19T03:59:13.553Z
It’s a “mapping from the inside” issue. As with equatorial coordinates, the longitude coordinate increases to the left (when North is up). See https://astronomy.stackexchange.com/questions/16339/what-is-the-galactic-latitude-and-galactic-longitude-how-is-different-from-the
Peter Erwin
<coordinate><python><astropy><visualization>
How to plot celestial equator in galactic coordinates? Why does my plot appear "backwards"?
Michael Belvedersky
# How to plot celestial equator in galactic coordinates? Why does my plot appear "backwards"?

(Asked by: username_0 on 2020-10-16)

I'm trying to plot celestial equator in galactic coordinates. Here is my code (based on this answer):
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import numpy as np

from astropy.coordinates import SkyCoord
from astropy import units as u

ra_all = np.linspace(-180, 180, 100)
dec_0 = np.zeros(100)

# Transform equatorial coordinates to galactic
eq = SkyCoord(ra_all, dec_0, unit=u.deg)
gal = eq.galactic
l_plot, b_plot = gal.l.wrap_at('180d').radian, gal.b.radian


lon = np.linspace(0, 360, 100)
lat = np.zeros(100)

# Transform ecliptic coordinates to galactic
ecl = SkyCoord(lon, lat, unit=u.deg, frame='barycentricmeanecliptic')
ecl_gal = ecl.transform_to('galactic')
l_ecl_gal, b_ecl_gal = ecl_gal.l.wrap_at('180d').radian, ecl_gal.b.radian


plt.figure(figsize=(14,7))
plt.subplot(111, projection='aitoff')

plt.scatter(l_plot, b_plot, s=5, label='Celestial Equator')
plt.scatter(l_ecl_gal, b_ecl_gal, s=5, label='Eclptic')


plt.grid(True)
plt.legend(fontsize=16)

plt.show()


However, the map I drew seems to be flipped left to right compared to the one bellow (taken from here)


Question 1: Why does the result of my implementation appear to be the reverse of the other image? Do I have something wrong, or is this simply an issue of mapping the surface from the inside versus from the outside?
Question 2: What is the best way to change my code to make it draw galactic map in a conventional format?

**Tags:** coordinate, python, astropy, visualization

> **Comments:**
> **username_1**: I adjusted your wording a little bit to better fit the site. I think this is an interesting question and might have an interesting answer!  
> **username_2**: It’s a “mapping from the inside” issue. As with equatorial coordinates, the longitude coordinate increases to the left (when North is up). See https://astronomy.stackexchange.com/questions/16339/what-is-the-galactic-latitude-and-galactic-longitude-how-is-different-from-the  

---

## 1 answers

### Answer by username_0 on 2020-10-21. Score: 4

Ok, community helped me to figure out that I faced the “mapping from the inside” issue (explained here). I'll use this answer to show my final code.
import numpy as np
from astropy.coordinates import SkyCoord
import astropy.units as u
import matplotlib.pyplot as plt
import seaborn as sns

sns.set()

def eq2gal(ra, dec):
    
    '''
    Transforms equatorial coordinates to galactic ones.
    Then prepares them for matplotlib aitoff projection. 
    '''
    
    eq = SkyCoord(ra, dec, unit=u.deg)
    gal = eq.galactic

    # Minus appears because of “mapping from the inside” issue
    l_gal, b_gal = -gal.l.wrap_at('180d').radian, gal.b.radian
    
    return l_gal, b_gal

def ecl2gal(lon_ecl, lat_ecl):
    
    '''
    Transforms ecliptic coordinates to galactic ones.
    Then prepares them for matplotlib aitoff projection.
    '''
    
    ecl = SkyCoord(lon_ecl, lat_ecl, unit=u.deg, frame='barycentricmeanecliptic')
    gal = ecl.transform_to('galactic')

    # Minus appears because of “mapping from the inside” issue
    l_gal, b_gal = -gal.l.wrap_at('180d').radian, gal.b.radian
    
    return l_gal, b_gal

# Equatorial plane
ra_all = np.linspace(-180, 180, 100)
dec_0 = np.zeros(100)

l_eq_gal, b_eq_gal = eq2gal(ra_all, dec_0)

# Ecliptic plane
lon_ecl = np.linspace(0, 360, 100)
lat_ecl = np.zeros(100)

l_ecl_gal, b_ecl_gal = ecl2gal(lon_ecl, lat_ecl)


plt.figure(figsize=(14,7))
plt.subplot(111, projection='aitoff')

plt.scatter(l_eq_gal, b_eq_gal, s=4, marker='v', label='Celestial Equator')
plt.scatter(l_ecl_gal, b_ecl_gal, s=4, marker='^', label='Eclptic')

# Essential thing is to rename RA axis ticks to transform them to conventional format
plt.xticks(ticks=np.radians([-150, -120, -90, -60, -30, 0, \
                             30, 60, 90, 120, 150]),
           labels=['150°', '120°', '90°', '60°', '30°', '0°', \
                   '330°', '300°', '270°', '240°', '210°'])


plt.grid(True)
plt.legend(fontsize=16, loc='lower center')

plt.title('Galactic', fontsize='16')

plt.show()


---

