0

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?

tomasz74
  • 16,031
  • 10
  • 37
  • 51
  • http://stackoverflow.com/questions/5179589/how-to-achieve-continuous-3d-plotting-i-e-update-a-figure-using-python-and-ma – Joran Beasley Oct 01 '12 at 18:47
  • possible duplicate of [pylab.ion() in python 2, matplotlib 1.1.1 and updating of the plot while the program runs](http://stackoverflow.com/questions/12822762/pylab-ion-in-python-2-matplotlib-1-1-1-and-updating-of-the-plot-while-the-pro) – Mechanical snail Jun 05 '13 at 23:34

2 Answers2

3

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

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199
0
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)
Lepy
  • 1
  • 1
  • @Lepy I try to implement your solution but it doesn't want to work. I cannot change lines `pl.plt.plot(myDict[key])` and `pl.plt.plot(x)` as in the original problem they are implemented in different script. When I try as it stands, the figure does not show I try different things but now lack. How would you write with multpiple `plot()` functions to display on one figure? And also do you know how to have the figure in the whole screen? – tomasz74 Oct 01 '12 at 19:53