Created
April 2, 2020 14:55
-
-
Save kervel/444a8faa9be2cc3ab745d234ebc95299 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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