from ipywidgets import interact, fixed
import ipywidgets as widgets
from bqplot import pyplot as plt
import numpy as np
from numpy.random import rand
def f(x):
return x**2
interact(f, x=10.);
interactive(children=(FloatSlider(value=10.0, description='x', max=30.0, min=-10.0), Output()), _dom_classes=(…
mon_slider = widgets.FloatSlider(
value=1,
min=-10,
max=30,
step=0.1,
description='x',
disabled=False,
continuous_update=True,
orientation='horizontal',
readout = True
)
resultat = widgets.Output()
def maj_resultat(change):
with resultat:
resultat.clear_output()
print(f(change['new']))
mon_slider.observe(maj_resultat, names='value')
display(mon_slider,resultat)
FloatSlider(value=1.0, description='x', max=30.0, min=-10.0)
Output()
from ipywidgets import interact, fixed
import ipywidgets as widgets
from bqplot import pyplot as plt
import numpy as np
from numpy.random import rand
#génère des abscisses
x = np.arange(0,10,0.1)
#trace une figure y = f(x)
ma_figure = plt.figure(animation_duration = 300)
mon_tracé = plt.scatter(x, x**2, enable_move=True)
plt.xlabel('Axe des x')
resultat2 = widgets.Output()
#choix de la fonction à tracer
@interact(fonction=['parabole', 'sinus', 'hasard'], x=fixed(x))
def choix_fonction(fonction, x):
if fonction=='parabole':
with mon_tracé.hold_sync():
mon_tracé.x = x
mon_tracé.y = x**2
plt.ylabel('x au carré')
if fonction=='sinus':
with mon_tracé.hold_sync():
mon_tracé.x = x
mon_tracé.y = np.sin(x)
plt.ylabel('sin(x)')
if fonction=='hasard':
with mon_tracé.hold_sync():
mon_tracé.x = x
mon_tracé.y = rand(len(x))
plt.ylabel('Nombres aléatoires')
#fonction qui lit et affiche les coordonnées d'un point déplacé
def affiche(name, value):
with resultat2:
resultat2.clear_output()
print('Le point n° %i a été déplacé en x = %f y = %f'
%(value['index'], value['point']['x'],value['point']['y']))
#détecte le déplacement d'un point
mon_tracé.on_drag_end(affiche)
#créé la gui
widgets.VBox([ma_figure,resultat2])
interactive(children=(Dropdown(description='fonction', options=('parabole', 'sinus', 'hasard'), value='parabol…
VBox(children=(Figure(animation_duration=300, axes=[Axis(label='Axe des x', scale=LinearScale()), Axis(label='…