Skip to content

Instantly share code, notes, and snippets.

@kervel
Created April 2, 2020 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kervel/444a8faa9be2cc3ab745d234ebc95299 to your computer and use it in GitHub Desktop.
Save kervel/444a8faa9be2cc3ab745d234ebc95299 to your computer and use it in GitHub Desktop.
# create some control elements
int_slider = widgets.IntSlider(value=1, min=0, max=10, step=1, description='freq')
color_picker = widgets.ColorPicker(value=initial_color, description='pick a color')
text_xlabel = widgets.Text(value='', description='xlabel', continuous_update=False)
text_ylabel = widgets.Text(value='', description='ylabel', continuous_update=False)
# callback functions
def update(change):
"""redraw line (update plot)"""
line.set_ydata(np.sin(change.new * x))
fig.canvas.draw()
def line_color(change):
"""set line color"""
line.set_color(change.new)
def update_xlabel(change):
ax.set_xlabel(change.new)
def update_ylabel(change):
ax.set_ylabel(change.new)
# connect callbacks and traits
int_slider.observe(update, 'value')
color_picker.observe(line_color, 'value')
text_xlabel.observe(update_xlabel, 'value')
text_ylabel.observe(update_ylabel, 'value')
text_xlabel.value = 'x'
text_ylabel.value = 'y'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment