2

I would like to know if there is any way to include a plot which can interactively change using slider controls in a Beamer presentation.

For example, I would like to show the following ipython interactive plot

from ipywidgets import widgets, Layout, Button, Box
from IPython.display import display
import matplotlib.pyplot as plt
import numpy as np
%matplotlib notebook

x = np.linspace(0, 2 , 1000)
fig, ax =plt.subplots(1, figsize=(10,4))
plt.suptitle('Sine Wave')

def update_plot(amp, phase, freq):
    ax.clear()
    units = 'amp = {} $(\phi)$ \nphase = {}  $s$ \nfreq = {} $Hz$'
    y = amp*np.sin(2*np.pi*(freq*x+phase))
    ax.plot(x,y, label=units.format(amp, phase, freq))
    ax.legend(loc=1)
    ax.set_xlabel('seconds')
    ax.set_ylabel('Amplitud')
    ax.set_xlim(x[0], x[-1])
    plt.show()

amp1 = widgets.FloatSlider(min=1, max=10, value=4, description= 'Amp:')
phase1 = widgets.FloatSlider(min=0, max=5, value=0, description= 'Phase:')
freq1 = widgets.FloatSlider(min=1, max=10, value=1, description= 'Freq:')
widgets.interactive(update_plot,amp=amp1, phase=phase1, freq=freq1)

Showing a plot with three controls: amplitude, phase, and frequency of a sine function.

enter image description here

Beamer allows to embed movies with a multimedia package but surely it is possible to use a python code of a Jupiter notebook in a presentation.

user1993416
  • 1,046
  • if you can show a PDF file that embeds a jupyter notebook then someone could show how to generate such a pdf from tex, but personally I have some doubts that that is possible. You could of course link to a web hosted jupyter notebook from a pdf. – David Carlisle Jul 09 '18 at 09:34
  • @DavidCarlisle thanks. I do not know how to create a PDF with an interactive plot. – user1993416 Jul 09 '18 at 09:54
  • 2
    Embedded Flash (SWF) is your only option, currently. (And you need AR or Foxit for viewing.): https://tex.stackexchange.com/a/98686 – AlexG Jul 09 '18 at 10:02
  • 1
    @user1993416 basically you can't embed the jupyter interaction in a pdf so there is not much that can be done from the tex side. as Alex just said some pdf viewers still allow flash but I wouldn't know how to generate flash from python and it doesn't sound a very good long term solution. Just link from your pdf presentation to your jupyter notebook if you want a "live demo" mid-presentation. – David Carlisle Jul 09 '18 at 10:08

0 Answers0