Franny Dean commited on
Commit
c8eaa36
1 Parent(s): 97f0f9a

attempt figure animation

Browse files
Files changed (2) hide show
  1. .ipynb_checkpoints/app-checkpoint.py +19 -20
  2. app.py +19 -20
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -458,11 +458,11 @@ def pvloop_simulator(Rm, Ra, Emax, Emin, Vd, Tc, start_v):
458
  fig, ax = plt.subplots()
459
  plt.ylim((0,220))
460
  plt.xlim((0,250))
461
- line = ax.plot(volumes[(N-2)*60000], pressures[(N-2)*60000], lw=1)
462
- #line = ax.plot(volumes[(N-2)*60000:(N)*60000], pressures[(N-2)*60000:(N)*60000], lw=1)
463
- #print(line)
464
- line = line[0]
465
- #print(line)
466
 
467
  fig.suptitle('Predicted PI-SSL LV Pressure Volume Loop', fontsize=16)
468
  #plt.rcParams['fig.suptitle'] = -2.0
@@ -474,14 +474,13 @@ def pvloop_simulator(Rm, Ra, Emax, Emin, Vd, Tc, start_v):
474
  # fig.subplots_adjust(left=0.25, bottom=0.25)
475
 
476
  def update(frame):
477
- # for each frame, update the data stored on each artist.
478
- x = volumes[:(N-2)*60000+frame]
479
- y = pressures[:(N-2)*60000:(N)+frame]
480
- line.set_xdata(x)
481
- line.set_ydata(y)
482
- return line
483
-
484
- anim = animation.FuncAnimation(fig=fig, func=update, frames=40, interval=30)
485
 
486
  return plt, Rm, Ra, Emax, Emin, Vd, Tc, start_v
487
 
@@ -551,13 +550,13 @@ with gr.Blocks() as demo:
551
 
552
 
553
  with gr.Row():
554
- sl1 = gr.Slider(0.005, 0.1, value=Rm, label="Rm")
555
- sl2 = gr.Slider(0.0001, 0.25, value=Ra, label="Ra")
556
- sl3 = gr.Slider(0.5, 3.5, value=Emax, label="Emax")
557
- sl4 = gr.Slider(0.02, 0.1, value= Emin, label="Emin")
558
- sl5 = gr.Slider(4.0, 25.0, value=Vd, label="Vd")
559
- sl6 = gr.Slider(0.4, 1.7, value=Tc, label="Tc")
560
- sl7 = gr.Slider(0.0, 280.0, value=start_v, label="start_v")
561
 
562
 
563
  generate_button.click(fn=generate_example, outputs = [video,plot,Rm,Ra,Emax,Emin,Vd,Tc,start_v])
 
458
  fig, ax = plt.subplots()
459
  plt.ylim((0,220))
460
  plt.xlim((0,250))
461
+ start = (N-2)*60000
462
+ end = (N-2)*60000+50000
463
+ line = ax.plot(volumes[start:(start+1)], pressures[start:(start+1)], lw=1, color='b')
464
+ point = ax.scatter(volumes[start:(start+1)], pressures[start:(start+1)], c="b", s=5)
465
+
466
 
467
  fig.suptitle('Predicted PI-SSL LV Pressure Volume Loop', fontsize=16)
468
  #plt.rcParams['fig.suptitle'] = -2.0
 
474
  # fig.subplots_adjust(left=0.25, bottom=0.25)
475
 
476
  def update(frame):
477
+ # update to add more of the loop
478
+ end = (N-2)*60000+1000 * frame
479
+ x = volumes[start:end]
480
+ y = pressures[start:end]
481
+ ax.plot(x, y, lw=1, c='b')
482
+
483
+ anim = animation.FuncAnimation(fig, partial(update), frames=43, interval=1)
 
484
 
485
  return plt, Rm, Ra, Emax, Emin, Vd, Tc, start_v
486
 
 
550
 
551
 
552
  with gr.Row():
553
+ sl1 = gr.Slider(0.005, 0.1, value=.005, label="Rm")
554
+ sl2 = gr.Slider(0.0001, 0.25, value=.0001, label="Ra")
555
+ sl3 = gr.Slider(0.5, 3.5, value=.5, label="Emax")
556
+ sl4 = gr.Slider(0.02, 0.1, value= .02, label="Emin")
557
+ sl5 = gr.Slider(4.0, 25.0, value= 4.0, label="Vd")
558
+ sl6 = gr.Slider(0.4, 1.7, value= 0.4, label="Tc")
559
+ sl7 = gr.Slider(0.0, 280.0, value= 140., label="start_v")
560
 
561
 
562
  generate_button.click(fn=generate_example, outputs = [video,plot,Rm,Ra,Emax,Emin,Vd,Tc,start_v])
app.py CHANGED
@@ -458,11 +458,11 @@ def pvloop_simulator(Rm, Ra, Emax, Emin, Vd, Tc, start_v):
458
  fig, ax = plt.subplots()
459
  plt.ylim((0,220))
460
  plt.xlim((0,250))
461
- line = ax.plot(volumes[(N-2)*60000], pressures[(N-2)*60000], lw=1)
462
- #line = ax.plot(volumes[(N-2)*60000:(N)*60000], pressures[(N-2)*60000:(N)*60000], lw=1)
463
- #print(line)
464
- line = line[0]
465
- #print(line)
466
 
467
  fig.suptitle('Predicted PI-SSL LV Pressure Volume Loop', fontsize=16)
468
  #plt.rcParams['fig.suptitle'] = -2.0
@@ -474,14 +474,13 @@ def pvloop_simulator(Rm, Ra, Emax, Emin, Vd, Tc, start_v):
474
  # fig.subplots_adjust(left=0.25, bottom=0.25)
475
 
476
  def update(frame):
477
- # for each frame, update the data stored on each artist.
478
- x = volumes[:(N-2)*60000+frame]
479
- y = pressures[:(N-2)*60000:(N)+frame]
480
- line.set_xdata(x)
481
- line.set_ydata(y)
482
- return line
483
-
484
- anim = animation.FuncAnimation(fig=fig, func=update, frames=40, interval=30)
485
 
486
  return plt, Rm, Ra, Emax, Emin, Vd, Tc, start_v
487
 
@@ -551,13 +550,13 @@ with gr.Blocks() as demo:
551
 
552
 
553
  with gr.Row():
554
- sl1 = gr.Slider(0.005, 0.1, value=Rm, label="Rm")
555
- sl2 = gr.Slider(0.0001, 0.25, value=Ra, label="Ra")
556
- sl3 = gr.Slider(0.5, 3.5, value=Emax, label="Emax")
557
- sl4 = gr.Slider(0.02, 0.1, value= Emin, label="Emin")
558
- sl5 = gr.Slider(4.0, 25.0, value=Vd, label="Vd")
559
- sl6 = gr.Slider(0.4, 1.7, value=Tc, label="Tc")
560
- sl7 = gr.Slider(0.0, 280.0, value=start_v, label="start_v")
561
 
562
 
563
  generate_button.click(fn=generate_example, outputs = [video,plot,Rm,Ra,Emax,Emin,Vd,Tc,start_v])
 
458
  fig, ax = plt.subplots()
459
  plt.ylim((0,220))
460
  plt.xlim((0,250))
461
+ start = (N-2)*60000
462
+ end = (N-2)*60000+50000
463
+ line = ax.plot(volumes[start:(start+1)], pressures[start:(start+1)], lw=1, color='b')
464
+ point = ax.scatter(volumes[start:(start+1)], pressures[start:(start+1)], c="b", s=5)
465
+
466
 
467
  fig.suptitle('Predicted PI-SSL LV Pressure Volume Loop', fontsize=16)
468
  #plt.rcParams['fig.suptitle'] = -2.0
 
474
  # fig.subplots_adjust(left=0.25, bottom=0.25)
475
 
476
  def update(frame):
477
+ # update to add more of the loop
478
+ end = (N-2)*60000+1000 * frame
479
+ x = volumes[start:end]
480
+ y = pressures[start:end]
481
+ ax.plot(x, y, lw=1, c='b')
482
+
483
+ anim = animation.FuncAnimation(fig, partial(update), frames=43, interval=1)
 
484
 
485
  return plt, Rm, Ra, Emax, Emin, Vd, Tc, start_v
486
 
 
550
 
551
 
552
  with gr.Row():
553
+ sl1 = gr.Slider(0.005, 0.1, value=.005, label="Rm")
554
+ sl2 = gr.Slider(0.0001, 0.25, value=.0001, label="Ra")
555
+ sl3 = gr.Slider(0.5, 3.5, value=.5, label="Emax")
556
+ sl4 = gr.Slider(0.02, 0.1, value= .02, label="Emin")
557
+ sl5 = gr.Slider(4.0, 25.0, value= 4.0, label="Vd")
558
+ sl6 = gr.Slider(0.4, 1.7, value= 0.4, label="Tc")
559
+ sl7 = gr.Slider(0.0, 280.0, value= 140., label="start_v")
560
 
561
 
562
  generate_button.click(fn=generate_example, outputs = [video,plot,Rm,Ra,Emax,Emin,Vd,Tc,start_v])