I have a Choropleth map in which I would like to place points based on a drop down and only update the points not the whole map if an other option is chosen in the drop down.
Currently I am struggling to add a choropleth map and scatter plot at all. Here is my code:
Geeting values where to set the point;
dff_03_02 = df_03[((df_03["Jahr"] == (slider1_year)) & (df_03["AGS"] == selected_ags))]
latlon_where_ags_is = gem_map[gem_map['AGS'] == dff_03_02.iloc[0]['AGS']]
lat = latlon_where_ags_is.iloc[0]['lat']
lon = latlon_where_ags_is.iloc[0]['lon']
Trying to add geo_scatter to the choropleth:
fig=go.Figure(px.choropleth(dff_03_01, featureidkey='properties.AGS', geojson=gem_map, locations='AGS',
color=dff_03_01[drop2_ken], range_color=(
df_03[drop2_ken].min(), df_03[drop2_ken].max()),
projection="mercator", color_continuous_scale="Viridis", hover_name='Name'))
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(autosize=True,
margin={"r": 0, "t": 40, "l": 10, "b": 0},
title_text=legend_str
)
fig.update_layout(coloraxis_colorbar_x=-0.1,)
fig.add_trace(go.Figure(px.scatter_geo(
lat=[lat],
lon=[lon])))
Resulting error:
Traceback (most recent call last):
File "c:\DEV\proto_dash\proto_dash\pages\befo_gem\befo_gem.py", line 325, in update_my_graph2
fig.add_trace(go.Figure(px.scatter_geo(
File "C:\Users\lfstat-krep\AppData\Roaming\Python\Python310\site-packages\plotly\graph_objs\_figure.py", line 865, in add_trace
return super(Figure, self).add_trace(
File "C:\Users\lfstat-krep\AppData\Roaming\Python\Python310\site-packages\plotly\basedatatypes.py", line 2097, in add_trace
return self.add_traces(
File "C:\Users\lfstat-krep\AppData\Roaming\Python\Python310\site-packages\plotly\graph_objs\_figure.py", line 945, in add_traces
return super(Figure, self).add_traces(
File "C:\Users\lfstat-krep\AppData\Roaming\Python\Python310\site-packages\plotly\basedatatypes.py", line 2181, in add_traces
data = self._data_validator.validate_coerce(data)
File "C:\Users\lfstat-krep\AppData\Roaming\Python\Python310\site-packages\_plotly_utils\basevalidators.py", line 2687, in validate_coerce
self.raise_invalid_elements(invalid_els)
File "C:\Users\lfstat-krep\AppData\Roaming\Python\Python310\site-packages\_plotly_utils\basevalidators.py", line 304, in raise_invalid_elements
raise ValueError(
ValueError:
Invalid element(s) received for the 'data' property of
Invalid elements include: [Figure({
'data': [{'geo': 'geo',
'hovertemplate': 'lat=%{lat}<br>lon=%{lon}<extra></extra>',
'lat': array([48.1531077]),
'legendgroup': '',
'lon': array([11.54707286]),
'marker': {'color': '#636efa', 'symbol': 'circle'},
'mode': 'markers',
'name': '',
'showlegend': False,
'type': 'scattergeo'}],
'layout': {'geo': {'domain': {'x': [0.0, 1.0], 'y': [0.0, 1.0]}},
'legend': {'tracegroupgap': 0},
'margin': {'t': 60},
'template': '...'}
})]
The 'data' property is a tuple of trace instances
that may be specified as:
- A list or tuple of trace instances
(e.g. [Scatter(...), Bar(...)])
- A single trace instance
(e.g. Scatter(...), Bar(...), etc.)
- A list or tuple of dicts of string/value properties where:
- The 'type' property specifies the trace type
One of: ['bar', 'barpolar', 'box', 'candlestick',
'carpet', 'choropleth', 'choroplethmapbox',
'cone', 'contour', 'contourcarpet',
'densitymapbox', 'funnel', 'funnelarea',
'heatmap', 'heatmapgl', 'histogram',
'histogram2d', 'histogram2dcontour', 'icicle',
'image', 'indicator', 'isosurface', 'mesh3d',
'ohlc', 'parcats', 'parcoords', 'pie',
'pointcloud', 'sankey', 'scatter',
'scatter3d', 'scattercarpet', 'scattergeo',
'scattergl', 'scattermapbox', 'scatterpolar',
'scatterpolargl', 'scattersmith',
'scatterternary', 'splom', 'streamtube',
'sunburst', 'surface', 'table', 'treemap',
'violin', 'volume', 'waterfall']
- All remaining properties are passed to the constructor of
the specified trace type
(e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])
Thank you!