I am trying to make an interactive plot in Jupyter, and it works somewhat with one problem, which is that every time I hit the button to generate a plot, a new plot is appended instead of the current one being replaced. Any ideas on how to fix this problem?
field_ddl = widgets.Dropdown(
options=['race', 'gender', 'grade'],
value='race',
description='field:',
disabled=False,
button_style='info'
)
graph_btn = widgets.Button(
description='graph',
disabled=False,
button_style='success',
tooltip='distribution plot',
icon='check'
)
def graph_btn_clicked(e):
field = field_ddl.value
df[field].value_counts().plot(kind='bar', title=field)
graph_btn.on_click(graph_btn_clicked)
display(field_ddl)
display(graph_btn)
I've looked up the interact feature, but that doesn't seem to help. Upon initialization, a graph is produced, but when the I select another field and hit the button again, nothing happens.
interact(graph_btn_clicked, x=graph_btn)