# Circle on scattermapbox with coordinates as reference

**URL:** <https://community.plotly.com/t/circle-on-scattermapbox-with-coordinates-as-reference/36633>\
**Category:** 📊 Plotly Python\
**Created:** [March 24, 2020, 4:33pm UTC](https://community.plotly.com/t/circle-on-scattermapbox-with-coordinates-as-reference/36633 "2020-03-24T16:33:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![meteoDan](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@meteoDan](https://community.plotly.com/u/meteoDan)\
**Post date:** [March 24, 2020, 4:33pm UTC](https://community.plotly.com/t/circle-on-scattermapbox-with-coordinates-as-reference/36633/1 "2020-03-24T16:33:31Z")

</div>

I want to add circles to a scattermapbox with WGS84 coordinates as center or x0,y0 and x1/y1 coordinates referenced to the coordinates on map and want to size refernced to the map. Means by a radius in kilometers or in degrees.

I hope anyone has a solution.

---

<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:** [March 25, 2020, 10:49am UTC](https://community.plotly.com/t/circle-on-scattermapbox-with-coordinates-as-reference/36633/2 "2020-03-25T10:49:49Z")

</div>

@meteoDan

This a question for `gis.stackexchange`. Here we can only suggest how to draw on a Scattermapbox chart, a line representing a circle, once you found out its equation in lon and lat coordinates used by Mapbox

Here is the code for plotting a circle as in a cartesian system with lon, lat interpreted as x, y coordinates It can be used as model when you have found out the actual parametric equation:

```auto
import numpy as np
from numpy import pi, sin, cos
import plotly.graph_objs as go

fig = go.Figure(go.Scattermapbox(
                    lat=[45.46427],
                    lon=[9.18951],
                    mode='markers',
                    text='Milan',
                    marker_size=9, marker_color='red',
                    hoverinfo='text'))

R = 0.75
center_lon = 9.18951
center_lat = 45.46427
t = np.linspace(0, 2*pi, 100)
circle_lon =center_lon + R*cos(t)
circle_lat =center_lat + R*sin(t)

coords=[]
for lo, la in zip(list(circle_lon), list(circle_lat)):
    coords.append([lo, la]) 

layers=[dict(sourcetype = 'geojson',
             source={ "type": "Feature",
                     "geometry": {"type": "LineString",
                                  "coordinates": coords
                                  }
                    },
             color= 'red',
             type = 'line',   
             line=dict(width=1.5)
            )]

fig.update_layout(
    title_text='Your title',
    width=850,
    height=850,
    mapbox=dict(
        accesstoken=mapbox_access_token,
        layers=layers,
        bearing=0,
        center=dict(
            lat=45.8257,
            lon=10.8746, 
        ),
        pitch=0,
        zoom=5.6,
        style='outdoors')
   )

```
