Overlay maps in Plotly + Mapbox

Hi!

I would like to display 2 data layers on the same map. One contains polygons and the other contains points. Right now I have them in 2 separate maps, something like this:

   fig = px.choropleth_mapbox(coverage_lte_df, geojson=geojson_polygons, locations='name', color='scoring',
                           color_continuous_scale="Viridis",
                           #range_color=(50, 100),
                           mapbox_style="carto-positron",
                           zoom=10, center = {"lat": centroid[0], "lon": centroid[1]},
                           opacity=0.5
                           )
   fig2 = px.scatter_mapbox(coverage_lte_df, lat="latitude", lon="longitude", hover_name="name", hover_data=["scoring"],
                        color_discrete_sequence=["fuchsia"], zoom=10, height=300)

Is there any way to combine these two maps? I have been searching online and in this forum without finding a clear answer

Thanks a lot in advance!!

1 Like

Hi,

I got some tips from the following thread:

And I was able to overlay the two maps like this:

   trace0 = fig2 # the second map from the previous code
   fig.add_trace(trace0.data[0])
   trace0.layout.update(showlegend=False)

BR

1 Like