I have two separate map plots, one is cultural boundaries in a country (just like the state borders) in the form of custom polygons based on latitude and longitude values, defined in geojson format. I can plot the polygons easily using geopandas:
states = gpd.read_file('myfile.geojson')
states.boundary.plot()
Here is a sample output:
The second is a series of latitudes and longitudes with corresponding values that I need to plot over a map layer, which I can do with plotly express's scatter_mapbox:
fig = px.scatter_mapbox(df_year,
lat='y', lon='x',
color='drought_index',
range_color=(-4, 4),
hover_data={'x': False, 'y': False},
zoom=5, height=800, width=1050,
center={'lat': 32.7089, 'lon': 53.6880},
color_continuous_scale=px.colors.diverging.RdYlGn,
color_continuous_midpoint=0,
)
fig.update_layout(mapbox_style="outdoors", mapbox_accesstoken=mb_token)
Which will look like this:
Is there any way to add these two plots together and have the scatter points and shape boundaries overlap on a single map? Meaning that on top of the mapbox layer, I have the scatter points and the boundaries of the polygons visible.
The problem is that geopandas plot uses matplotlib and returens AxesSubplot:, and I couldn't find any way to add this to the plotly fig. I tried the mpl_to_plotly() from plotly.tools, but it threw an exception on 'Canvas is null'.
I also tried to find a way to plot the geojson shapes with plotly, but all I could find was the choropleth mapbox which requires the shapes to be filled with a color. I tried to use it anyways by decreasing the opacity of the choropleth plot but it either will cover the scatter plot or be barely visible.
Any suggestion on how to approach this is appreciated.


