# Plotly Scattermapbox positive to negative longitudes

**URL:** <https://community.plotly.com/t/plotly-scattermapbox-positive-to-negative-longitudes/37748>\
**Category:** 📊 Plotly Python\
**Created:** [April 14, 2020, 5:49am UTC](https://community.plotly.com/t/plotly-scattermapbox-positive-to-negative-longitudes/37748 "2020-04-14T05:49:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dm1681](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dm1681](https://community.plotly.com/u/dm1681)\
**Post date:** [April 14, 2020, 5:49am UTC](https://community.plotly.com/t/plotly-scattermapbox-positive-to-negative-longitudes/37748/1 "2020-04-14T05:49:54Z")

</div>

Hello! I am trying to make a scattermapbox using plotly and am running into some issues:

I am trying to plot a filled area using the following coordinates:

lats = [17,7, 13, 15, 17]  
lons = [-170, 100, 136, 153, -170]

The problem I am running into is how go.Scattermapbox is displaying the lines. Instead of drawing a line connecting longitude 100 to -170 and crossing the 180 meridian, it draws the line all the way around the world (Please view the attached image). I believe this is due to my points straddling -180 degrees longitude. If I just add 360 to the 170, it is displayed correctly, however that just moves the problem to values that straddle 0 degrees longitude (prime meridian). Has anyone else encountered this? How do you fix this issue?

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/8/8279f82ebdd1aad1d0a9ab48595b92bbaf3275f2.png)

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [April 15, 2020, 7:49am UTC](https://community.plotly.com/t/plotly-scattermapbox-positive-to-negative-longitudes/37748/2 "2020-04-15T07:49:47Z")

</div>

Hi @dm1681,  
Reorder your data, and replace -170 by 190 (if we are identifying 180 with -180, then -170 gets 190).

lat = [7, 13,15,17]  
lon= [100, 136, 153, 190]

With these data you’ll get the right plot:

```auto
fig=go.Figure(go.Scattermapbox(lat=lat, lon=lon, fill='toself'))#190 represents -170

fig.update_layout(height=600,
    
    mapbox=dict(
        accesstoken='',
        bearing=0,
        center=dict(
                         lat=12,
                         lon=145 ),
        pitch=0,
        zoom=1,
        style='basic'
    )
)

fig.show()

```

Eventually you can add customdata and hovertemplate to get displayed on hover the right lon ,-170, instead of 190.  
.

---

<div class="post-metadata">

**Author:** ![dm1681](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dm1681](https://community.plotly.com/u/dm1681)\
**Post date:** [April 15, 2020, 8:01pm UTC](https://community.plotly.com/t/plotly-scattermapbox-positive-to-negative-longitudes/37748/3 "2020-04-15T20:01:52Z")

</div>

Yes, I had already come to that solution (by adding 360) and mentioned it in my post. I was not sure how to apply that solution generically. For instance, if I do it for every longitude \< 0, then the same problem persists, except straddling 0 degrees longitude.

After some searching, I found that in order to determine which points needed to be mapped, I calculate relative distances between all the points and find the point that has the average distance \> 180. Then if that point is negative, I add 360, if it is positive, I subtract 360.
