Search code examples
pythonplotly

how to remove states from plotly Scattergeo trace?


I was reading through the Scattergeo documentation to remove Alaska and Hawaii from the 'usa' scoped without success. No functionality to access a specific subunit. Is there any workaround to perform this?

enter image description here


Solution

  • Ok, so this solved my issue. I had to superimpose a new trace. Take into account that the marker_line_color has to be set equal to your paper_bgcolor, once you got this, in order to avoid some aliasing between the Cholorpleth and the Scattergeo, set the marker_line_width to something bigger than the default value, e.g. 2.

    chorpleth = go.Choropleth(
            locationmode='USA-states',
            z=[0,0],
            locations=['AK','HI'],
            colorscale = [[0,'rgba(0, 0, 0, 0)'],[0,'rgba(0, 0, 0, 0)']],
            marker_line_color='#fafafa',
            marker_line_width=2,
            showscale = False,
        )
    
    fig.add_trace(chorpleth, row=1, col=1) 
    

    enter image description here