<p>Assuming</p>

<pre><code>x, y = rrl_pm.l, rrl_pm.b
</code></pre>

<p>The transformation you want is </p>

<pre><code>xx = [(q+180)%360 - 180 for q in x]
</code></pre>

<p>Add 180, do modulo 360, then subtract 180.</p>

<p>Then set your limits</p>

<pre><code>ax.set_xlim(180, -180)
</code></pre>

<p><img src="https://i.sstatic.net/k3wEG.png" alt="enter image description here"></p>

<p><img src="https://i.sstatic.net/6OfYr.png" alt="enter image description here"></p>

<pre><code>import matplotlib.pyplot as plt

x = (0, 10, 20, 40, 80, 160, 200, 280, 320, 340, 350)
y = (0, 10, 20, 30, 40, 50,  -50,  -40, -30, -20, -10)

fig = plt.figure(figsize=(8,5))
ax  = fig.add_subplot(1,1,1, aspect='equal')

ax.scatter(x, y)

ax.set_xlim(0, 360)
ax.set_ylim(-90., 90.)

plt.title('Old', fontsize=18)

plt.show()

xx = [(q+180)%360 - 180 for q in x]  # DO THIS!

fig = plt.figure(figsize=(8,5))
ax  = fig.add_subplot(1,1,1, aspect='equal')

ax.scatter(xx, y)

ax.set_xlim(180, -180)
ax.set_ylim(-90., 90.)

plt.title('New', fontsize=18)

plt.show()
</code></pre>

CC BY-SA 4.0
2019-06-11T13:01:09.690Z
2019-06-11T13:01:09.690Z
uhoh
<p>I made a scatter plot in Python that looks like this: </p>

<blockquote>
  <p><a href="https://i.sstatic.net/7STO3.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7STO3.jpg" alt="enter image description here"></a></p>
</blockquote>

<p>However, I want galactic longitude, l, to be plotted from 180 to -180 like these graphs from Iorio and Belokurov (2019): </p>

<blockquote>
  <p><a href="https://i.sstatic.net/1Ni5G.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1Ni5G.png" alt="enter image description here"></a>  </p>
</blockquote>

<p>Here is the code for my plot: </p>

<pre><code>sns.set_style("ticks")
sns.set_context("poster")
%matplotlib inline
from matplotlib import pyplot as plt

fig = plt.figure(figsize=(8,5))

ax  = fig.add_subplot(1,1,1, aspect='equal')

ax.scatter(rrl_pm.l, rrl_pm.b, s=1, color='black', alpha=0.1)

ax.set_xlim(0, 360)
ax.set_ylim(-90., 90.)

ax.set_xlabel("l [deg]")
ax.set_ylabel("b [deg]")
textstr = 'N = ' + str(len(rrl_pm.l))
props = dict(boxstyle='round', facecolor='white', alpha=0.5)
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=16,
        verticalalignment='top', bbox=props)
plt.title("Scatter Plot of Cleaned Sample of RRLs in Sgr dSph with Spatial AND PM Cuts", fontsize = 16)
plt.savefig("SP-Clean-Spatial-PM.png", dpi = 1000)
plt.show()
</code></pre>

<p>If I simply change the xlim to run from 180 to -180 degrees the following graph is produced:</p>

<p><a href="https://i.sstatic.net/RrfE1.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RrfE1.jpg" alt="enter image description here"></a></p>

<p>So essentially it only covers half the sky. Why exactly is this the case and what transformations do I need to apply to the galactic longitude for the 2nd plot to "wrap around" and display both sides? </p>

<coordinate><python>
Plotting Galactic Longitude from 180 to -180
astrlearn
# Plotting Galactic Longitude from 180 to -180

(Asked by: username_0 on 2019-06-10)

I made a scatter plot in Python that looks like this: 



However, I want galactic longitude, l, to be plotted from 180 to -180 like these graphs from Iorio and Belokurov (2019): 

 

Here is the code for my plot: 
sns.set_style("ticks")
sns.set_context("poster")
%matplotlib inline
from matplotlib import pyplot as plt

fig = plt.figure(figsize=(8,5))

ax  = fig.add_subplot(1,1,1, aspect='equal')

ax.scatter(rrl_pm.l, rrl_pm.b, s=1, color='black', alpha=0.1)

ax.set_xlim(0, 360)
ax.set_ylim(-90., 90.)

ax.set_xlabel("l [deg]")
ax.set_ylabel("b [deg]")
textstr = 'N = ' + str(len(rrl_pm.l))
props = dict(boxstyle='round', facecolor='white', alpha=0.5)
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=16,
        verticalalignment='top', bbox=props)
plt.title("Scatter Plot of Cleaned Sample of RRLs in Sgr dSph with Spatial AND PM Cuts", fontsize = 16)
plt.savefig("SP-Clean-Spatial-PM.png", dpi = 1000)
plt.show()

If I simply change the xlim to run from 180 to -180 degrees the following graph is produced:

So essentially it only covers half the sky. Why exactly is this the case and what transformations do I need to apply to the galactic longitude for the 2nd plot to "wrap around" and display both sides?

**Tags:** coordinate, python

---

## 1 answers

### Answer by username_1 on 2019-06-11. Score: 3 | Accepted answer

Assuming
x, y = rrl_pm.l, rrl_pm.b

The transformation you want is 
xx = [(q+180)%360 - 180 for q in x]

Add 180, do modulo 360, then subtract 180.
Then set your limits
ax.set_xlim(180, -180)



import matplotlib.pyplot as plt

x = (0, 10, 20, 40, 80, 160, 200, 280, 320, 340, 350)
y = (0, 10, 20, 30, 40, 50,  -50,  -40, -30, -20, -10)

fig = plt.figure(figsize=(8,5))
ax  = fig.add_subplot(1,1,1, aspect='equal')

ax.scatter(x, y)

ax.set_xlim(0, 360)
ax.set_ylim(-90., 90.)

plt.title('Old', fontsize=18)

plt.show()

xx = [(q+180)%360 - 180 for q in x]  # DO THIS!

fig = plt.figure(figsize=(8,5))
ax  = fig.add_subplot(1,1,1, aspect='equal')

ax.scatter(xx, y)

ax.set_xlim(180, -180)
ax.set_ylim(-90., 90.)

plt.title('New', fontsize=18)

plt.show()


---

