注释掉的行是我最好的猜测。
def _make_json(self, given_panda: pd.DataFrame, sort_by: str) -> str:
figure = px.scatter_mapbox(given_panda,
hover_name='City',
hover_data=['State', 'Average_Low', 'Average_High', 'Latitude', 'Longitude', 'Record_Low', 'Record_High', 'Wind', 'Elevation', 'Humidity', 'Total_Precip'],
color=sort_by,
color_continuous_scale=px.colors.sequential.Plasma,
zoom=3.4,
opacity=1,
lat='Latitude',
lon='Longitude',
center={'lat': 37.0902, 'lon': -95.7129},
mapbox_style='carto-darkmatter')
figure.update_layout(margin = {'r':0,'t':0,'l':0,'b':0})
#figure.update(layout = dict(legend = dict(bgcolor = 'red')))
return figure.to_json()
这可能会有所帮助 https://plotly.com/python/reference/#layout-showlegend