Commit f7d92c66 authored by Guillaume Garrigos's avatar Guillaume Garrigos
Browse files

correct weird bug in widget relative to stepsizes

parent 4ae22a15
......@@ -432,7 +432,7 @@ def widget_quadratic(**plot_param):
if plot_param['algo'] is not None:
slider_x0 = FloatSlider(description='$x_0$', value=1.0, **slider_param)
slider_y0 = FloatSlider(description='$y_0$', value=1.0, **slider_param)
slider_stepsize = FloatSlider(description='stepsize', value=1, min=0.01, max=2, step=0.05)
slider_stepsize = FloatSlider(description='stepsize', value=0.25, min=0.01, max=2, step=0.01)
# we initialize everything
A_slider = np.array([[slider_a11.value, slider_a12.value], [slider_a21.value, slider_a22.value]])
......@@ -441,9 +441,8 @@ def widget_quadratic(**plot_param):
if plot_param['algo'] is not None:
x0_slider = np.array([slider_x0.value, slider_y0.value])
plot_param['x0']= np.array([slider_x0.value, slider_y0.value])
stepsize_slider = slider_stepsize.value
plot_param['stepsize'] = slider_stepsize.value
#plot_param['sequence'] = sequence_gradient(A_slider, b_slider, x0_slider, stepsize_slider, **plot_param)
stepsize_slider = np.array([slider_stepsize.value])
plot_param['stepsize'] = np.array([slider_stepsize.value])
# open the figure
plt.ioff() # turn off interactive mode to be able to display widget. I honestly don't understand why. see or
......@@ -456,7 +455,10 @@ def widget_quadratic(**plot_param):
plot2d_function(quadratic(A_slider,b_slider), fig, **plot_param)
# the function handling the change of parameters
def update_plot(change, slider, idx):
# it seems that when stepsize/x0 is changed, the other parameter is reset
# but there is no such problem with the coefficients of A..?
# ok so more precisely :
def update_plot(change, slider, idx, plot_param):
# store the camera 3D view, then clears the figure
if 'graph' in plot_param.keys() and plot_param['graph']:
plot_param['azimuth'] = fig.get_axes()[0].azim # remember there are two subplots
......@@ -472,27 +474,29 @@ def widget_quadratic(**plot_param):
plot_param["title"] = print_info(A)
if plot_param['algo'] is not None:
plot_param['x0'] = x0_slider
plot_param['stepsize'] = stepsize_slider
plot_param['stepsize'] = stepsize_slider[0]
if slider == 'x0':
plot_param['x0'][idx] =
elif slider == 'stepsize':
if slider == 'stepsize':
stepsize_slider[0] = # why do we need to do that for this one specifically!?§ if not, when I change anything like A, x0, the stepsize is reset to the default value of the slider
plot_param['stepsize'] =
# plot
#plot_param["title"] = str(x0_slider) + str(stepsize_slider)
plot2d_function(quadratic(A,b), fig, **plot_param)
# keep track of changes
slider_a11.observe(lambda change : update_plot(change, 'A', (0,0)), names='value')
slider_a21.observe(lambda change : update_plot(change, 'A', (1,0)), names='value')
slider_a12.observe(lambda change : update_plot(change, 'A', (0,1)), names='value')
slider_a22.observe(lambda change : update_plot(change, 'A', (1,1)), names='value')
slider_b1.observe(lambda change : update_plot(change, 'b', (0,)), names='value')
slider_b2.observe(lambda change : update_plot(change, 'b', (1,)), names='value')
slider_a11.observe(lambda change : update_plot(change, 'A', (0,0), plot_param), names='value')
slider_a21.observe(lambda change : update_plot(change, 'A', (1,0), plot_param), names='value')
slider_a12.observe(lambda change : update_plot(change, 'A', (0,1), plot_param), names='value')
slider_a22.observe(lambda change : update_plot(change, 'A', (1,1), plot_param), names='value')
slider_b1.observe(lambda change : update_plot(change, 'b', (0,), plot_param), names='value')
slider_b2.observe(lambda change : update_plot(change, 'b', (1,), plot_param), names='value')
if plot_param['algo'] is not None:
slider_x0.observe(lambda change : update_plot(change, 'x0', (0,)), names='value')
slider_y0.observe(lambda change : update_plot(change, 'x0', (1,)), names='value')
slider_stepsize.observe(lambda change : update_plot(change, 'stepsize', None), names='value')
slider_x0.observe(lambda change : update_plot(change, 'x0', (0,), plot_param), names='value')
slider_y0.observe(lambda change : update_plot(change, 'x0', (1,), plot_param), names='value')
slider_stepsize.observe(lambda change : update_plot(change, 'stepsize', None, plot_param), names='value')
# now we display all of this
# a grid of sliders for the parameters
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment