Black Lives Matter. Please consider donating to Black Girls Code today.

Fill the inside of a Scattergeo polygon, not outside?

Hi,

I’m trying to render a filled circle with Scattergeo using the code below. When I set the fill mode to “toself”, the outside of the circle gets filled (i.e. all of the globe but the circled region is filled). How can I change the behavior to fill the inside of the circle?

import plotly.plotly as py
from plotly.graph_objs import *

import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)

lon_center = 45
lat_center = 0
radius = 5

thetas = np.linspace(0, 2*np.pi, 50)
lon = radius * np.cos(thetas) + lon_center
lat = radius * np.sin(thetas) + lat_center

trace1 = Scattergeo(
    lat=lat,
    line=Line(
        color='rgb(213,62,79)',
        width=3,
    ),
    fill="toself",
    lon=lon,
    mode='lines')

data = Data([trace1, trace2])
layout = Layout(
    geo=dict(
        lataxis=dict(
            gridcolor='rgb(102, 102, 102)',
            gridwidth=0.5,
            showgrid=True
        ),
        lonaxis=dict(
            gridcolor='rgb(102, 102, 102)',
            gridwidth=0.5,
            showgrid=True
        ),
        projection=dict(
            rotation=dict(
                lat=-10,
                lon=0,
                roll=-103
            ),
            type='orthographic'
        ),
        coastlinewidth=0
    ),
    showlegend=False,
)
fig = Figure(data=data, layout=layout)
iplot(fig)

I found that by incrementing my theta variable from zero to negative 2 pi, the interior of the circle was filled instead.

1 Like