Hello,
Here is a part of my code for plotting and adding traces to the plot.
I have two chained dropdown menus. With the first one, I can select the CSV file and store it as a Jason dataframe, and accordingly the options for the second dropdown menu updates based on the column names of the CSV file.
Now, for plotting, I want to have an initial 3d scatter plot based on the initial dataframe. Then, I want to do some changes (based on the selection in the second dropdown menu) and add them to the initial plot.
However, in my current code, I need to select from both dropdown menus, and then the figure shows the initial state and the updated one together. I want to plot the initial scatterplot when I chose from the first dropdown menu, and then plot the updated parts when I selected from the second dropdown menu.
@callback(
Output('graph3', 'figure'),
Input('table', 'data'),
Input('dropdown2', 'value'),
Input('my_rangeslider', 'value'),
#prevent_initial_call=True
)
def plot_trajectory(js_df, feature, ranges):
if (feature is None) or (ranges == []):
return dash.no_update
else:
dff = pd.read_json(js_df, orient='split')
fig = go.Figure()
fig.add_trace(go.Scatter3d(x=dff['EW'], y=dff['NS'], z=dff['length'], mode='markers', marker={'color': 'blue', 'size': 4}))
df_sliced = pd.concat([dff[(dff[feature] > ranges[1])], dff[(dff[feature] < ranges[0])]])
fig.add_trace(go.Scatter3d(x=df_sliced['EW'], y=df_sliced['NS'], z=df_sliced['length'], mode='markers', marker={'color': 'red', 'size': 6}))
fig.update_layout(hovermode='closest', margin={'l': 0, 'r': 0, 't': 30, 'b': 0}, showlegend=False, template="plotly_dark"),
fig.update_scenes(zaxis_autorange="reversed")
return fig