Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly Chloropleth combined with ScatterGeo

Can anyone help me spot the error here?

fig = go.Figure()

fig.add_trace(
    go.Choroplethmapbox(
        geojson=counties,
        locations=df_se['FIPS'], z=df_se['use_values'],
        colorscale="Viridis", zmin=min(df_se['use_values']), zmax=max(df_se['use_values']),
        marker_opacity=0.5, marker_line_width=0
    ))

fig.add_trace(
    go.Scattergeo(
        lon = df_jake['lng'],
        lat = df_jake['lat'],
        text = df_jake['Name']+', '+df_jake['Link'],
        mode = 'markers'
    ))
fig.update_layout()
fig.show()

It just shows up blank. I can plot Chloropleth and ScatterGeo seperately however

Thanks!

like image 353
mustacheMcGee Avatar asked Sep 27 '19 22:09

mustacheMcGee


People also ask

What is a choropleth map in Plotly?

We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials. A Choropleth Map is a map composed of colored polygons. It is used to represent spatial variations of a quantity.

What is scattergeo trace in Plotly?

A plotly.graph_objects.Scattergeo trace is a graph object in the figure's data list with any of the named arguments or attributes listed below. The data visualized as scatter point or lines on a geographic map is provided either by longitude/latitude pairs in `lon` and `lat` respectively or by geographic location IDs or names in `locations`.

What's new to Plotly?

New to Plotly? Plotly is a free and open-source graphing library for Python. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials. A Choropleth Map is a map composed of colored polygons.

Why do I need to use scattergeo?

The reason for my use of scattergeo is I'd like to plot a star symbol on top of the density mapbox, and the only symbol accepted via add_scattermapbox is a dot. If you choose the star symbol, there is no symbol added.


1 Answers

A bit of context: Choroplethmapbox makes choropleths on tile maps (example), whereas Scattergeo makes points on outline maps (example).

The scatter counterpart to Choroplethmapbox is Scattermapbox (example) and the choropleth counterpart to Scattergeo is Choropleth (example).

So the answer likely depends on what you are trying to do: if you're trying to show a choropleth and scatter data on a tile map, you'll want to switch from Scattergeo to Scattermapbox and if you want to show this data on an outline map, you'll want to switch from Choroplethmapbox to Choropleth.

like image 165
nicolaskruchten Avatar answered Oct 22 '22 15:10

nicolaskruchten