I hacked together this code to plot lat and lon coordinates on a map, and the code works pretty darn well, but I can't seem to get the legend displayed, so it's hard to tell what I'm actually looking at.
import pandas as pd
import pandas_bokeh
import matplotlib.pyplot as plt
import pgeocode
import geopandas as gpd
from shapely.geometry import Point
from geopandas import GeoDataFrame
pandas_bokeh.output_notebook()
import plotly.graph_objects as go
nomi = pgeocode.Nominatim('us')
df_melted['Latitude'] = (nomi.query_postal_code(df_melted['my_zip'].tolist()).latitude)
df_melted['Longitude'] = (nomi.query_postal_code(df_melted['my_zip'].tolist()).longitude)
df_melted['colors'] = df_melted['value'].groupby(df_melted['value']).transform('count')
print(df_melted.shape)
print(df_melted.head())
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
fig = go.Figure(data=go.Scattergeo(
lon = df_melted['Longitude'],
lat = df_melted['Latitude'],
text = df_melted['value'],
marker_color = df_melted['colors']
))
fig.update_layout(
autosize=False,
width=1000,
height=1000,
title = 'Footprints Compared Based on Lat & Lon Coordinates)',
geo_scope='usa',
showlegend=True
)
fig.update_layout(legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1
))
fig.show()
When I run the code, I see a nice map of the US, but there is not legend, even though I'm using this small script directly below, which came straight from the Plotly documentation.
legend=True & showlegend=True
Both gave me errors. Any idea how to get the legend to show up here?

