Some @interact questions

asked 2021-04-08 11:27:06 +0100

Cyrille gravatar image
 @interact
def _(a=slider([0,1,.01,0]),b=slider([0,1,0.01,0]),c=slider([.9,0,-.1])): 
    p=text(r"$1$",(2,10.6),color="black")
    p+=text(r"$0$",(2,9.4),color="black")
    p+=circle((1,10), 0.1, edgecolor='blue')
    p+=text(r"$A$",(1,10),color="black")
    p+=line([(1.2,10), (2,10)],color="red")
    p+=line([(2,9.5), (2,10.5)],color="red")
    p+= circle((2,9.5+a), 0.01,fill=True, edgecolor='red', facecolor='red')
    p+=line([(2,9.5+a), (2.5,9.5+a)],color="red")
    p+=text(r"$\lambda_0$",(2.25,9.6+a),color="black")
    p+=circle((1,10), 0.1, edgecolor='blue')
    p+=text(r"$B$",(2.8,9.5+a),color="black")
    p+=circle((2.8,9.5+a), 0.1, edgecolor='blue')
    p+=line([(3.2,9.5+a), (5.2,11+a)],color="green")
    p+=line([(3.2,9.5+a), (4.2,9+a)],color="green")
    p+=text(r"$(\lambda_0,1-\lambda_0)$",(4.5,8.75+a),color="black")
    p+=text((a,1-a),(4.5,8.5+a),color="black")
    p+=text(r"$a$",(3.7,9.1+a),color="black")
    p+=text(r"$r$",(4.2,10.5+a),color="black")
    p+=line([(5.2,10.5+a), (5.2,11.5+a)],color="green")
    p+=text(r"$1$",(5.2,11.6+a),color="black")
    p+=text(r"$0$",(5.2,10.4+a),color="black")
    p+= circle((5.2,10.5+a+b), 0.01,fill=True, edgecolor='green', facecolor='green')
    p+=line([(5.2,10.5+a+b), (5.7,10.5+a+b)],color="green")
    p+=text(r"$\lambda_1$",(5.45,10.6+a+b),color="black")
    p+=circle((6,10.5+a+b), 0.1, edgecolor='blue')
    p+=text(r"$A$",(6,10.5+a+b),color="black")
    p+=line([(6.3,10.5+a+b), (7.3,11.5+a+b)],color="red")
    p+=line([(6.3,10.5+a+b), (7.3,9.5+a+b)],color="red")
    p+=text(r"$a$",(6.8,9.8+a),color="black")
    p+=text(r"$r$",(6.8,11.2+a),color="black")
    p+=text(r"$(0,0)$",(7.75,11.7+a+b),color="black")
    p+=text(r"$(\beta \lambda_1,\beta(1-\lambda_1))$",(7.75,9.2+a+b),color="black")
    p+=text((c*b,c*(1-b)),(7.75,8.9+a+b),color="black")
    show(p,gridlines=False,axes=False, figsize=8)

1) This interaction is dramaticaly slow. Is there a way to increase its reaction ?

2) Could I use latex characters in the sliders

3) how coul I ask to display only round numbers (I have tried many solutions which doesn't work)

edit retag flag offensive close merge delete

Comments

Quick pointers :

  • use the keyword parameters rather than a cryptic list ;
  • dont't recompute the same quantities over again, buffer them in temporary variables ;
  • see the tutorial, which will show you that :
    • auto_update=False will avoid automatic (slow) redraw at each and every slider move ;
    • slider labels can contain \LaTeX;
  • round?

And, foremost, RTFM and the BD, especially the GT. You keep asking questions whose answer is already in the docs...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-04-08 14:00:49 +0100 )edit

Sory Emmanuel but some times the doc are very cryptic for me and more cryptic than all are the acronymes.

Cyrille gravatar imageCyrille ( 2021-04-08 14:30:13 +0100 )edit