On 2014/07/29, 7:04 PM, JBB wrote: > Hello, > > I am relatively new to Python, numpy, matplotlib, etc., with a > reasonable amount of Matlab experience. > > I am trying to do some simple array visualizations before moving on to > specific work. > > e.g. I have a 5x5x10 array and I'd like to see each 5x5 piece as a > "frame" with a short pause in between. I realize there are animation > methods and such but I think the code below ought to work and don't > understand what I'm getting. > > Expect: A figure window with the first 5x5 piece of the array, a short > pause, a new figure window overwriting the old one with the second 5x5 > piece, and so on. Equivalent code in Matlab does this. > > Result: Figure window opens, nothing gets drawn in it, there's a pause, > the window closes, and another window opens in the same location with > nothing in it, and so on. > > If I refresh the kernel, create the 3D array, and manually show one > slice, it works. As soon as I run the loop, all I get from then on is > blank windows whether I do it within a loop or type the matshow, show > commands. > > This happens in iPython with and without the notebook interface. > > I'm trying to understand Matplotlib in some detail and am watching the > SciPy2014 videos along with RTFM. > https://www.youtube.com/watch?v=A2adyFMsut0 et.seq. > > So far, I've come up empty in figuring out what I'm doing wrong. > > I have Python 2.7.8/Anaconda 2.0.1 > > Thanks, > > JBB > ===== Test code > > import numpy as np > from matplotlib.pylab import * > import time as time > > # Create a 3D array of "frames" > A = np.random.rand(5,5,10) > > #Turn on interactive mode > ion() > # Turn off interactive mode > # ioff() > > # Attempt to show each frame with a short delay between frames > for k in range(10): > matshow(A[:,:,k]) > show() > time.sleep(1) > close() >
First, at least initially for this sort of thing, run in "ipython --pylab", and don't use any "ion()" or "ioff()". Second, replace the "show(); time.sleep(1)" with "pause(1)". I think that will do it. Eric > > ------------------------------------------------------------------------------ > Infragistics Professional > Build stunning WinForms apps today! > Reboot your WinForms applications with our WinForms controls. > Build a bridge from your legacy apps to the future. > http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users