0
votes

I have a dictionary with data. For every entry I would like to display plots for 1 second and move to the next one. The plots to display are already coded in external scripts. I would like to do this automatically. So I loop through the dict, display first set of plots[0], close the plots[0], display plots[1] close plots[1] ... I would like to set up display time for let say 1 second and have the plot as full screen. The problem that during the presentation I don't want to touch the computer.

import pylab as pl
import numpy as np

x = np.arange(-np.pi, np.pi, 0.1)         # only for the example purpose
myDict = {"sin":np.sin(x), "cos":np.cos(x), "exp":np.exp(x)}
for key in myDict:
    print myDict[key]
    pl.plt.plot(myDict[key])              # in origin coming from external function
    pl.plt.plot(x)                        # in origin coming from external function
    pl.plt.show()

Does anyone know what function should be used and how to modify above?

2

2 Answers

3
votes

A simple method is to use plt.pause(1). A more sophisticated method is to usethe matplotlib.animate module. See pylab.ion() in python 2, matplotlib 1.1.1 and updating of the plot while the program runs

example, api, tutorial

0
votes
import time
import pylab as pl
import numpy as np

pl.ion()
x = np.arange(-np.pi, np.pi, 0.1)         # only for the example purpose
myDict = {"sin":np.sin, "cos":np.cos, "exp":np.exp}
for key in myDict:
    print myDict[key]
    pl.clf()
    y = myDict[key](x)
    pl.plt.plot(x, y, label=key)
    pl.plt.draw()
    time.sleep(1)