Hello, New to Dash. I’m trying to Patch a subplot to do things like adding an extra trace somewhere and such. It gives me this error when I use the add_trace()
function to the patched_figure = Patch()
.
This is my code.
app = Dash(__name__)
subplot = subplots.make_subplots(figure=None) # Define Subplot
app.layout = html.Div([
html.Button("Update Sublot", id="update-trace"),
dcc.Graph(figure=subplot, id="my-fig"),
])
@callback(Output("my-fig", "figure"), Input("update-trace", "n_clicks"))
def my_callback(n_clicks):
# Defining a new random trace
v = np.arange(-3, 5.1, 0.1) # x-axis
i = []
for each in v:
i.append(1e-3*(2*random.random() - 1)) # y-axis
# Creating a Patch object
patched_figure = Patch()
patched_figure.add_trace(go.Scatter(x=v, y=i, mode="lines"),
row=(1), col=(1)) # Adds trace at column and row
return patched_figure
if __name__ == "__main__":
app.run(debug=True)
Error:
patched_figure.add_trace(go.Scatter(x=v, y=i, mode=“lines”),
TypeError: ‘Patch’ object is not callable
I’ve searched and can only seem to find solutions that involve Patch()['data'].append(...)
but I think I also need the row
and col
parameters from add_trace()
to choose as well. Any ideas?