Re: [Matplotlib-users] Basic matshow question

2014-07-29 Thread JBB
On 7/29/14, 10:49 PM, Eric Firing wrote:
 > 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.

...[ Problem and test code trimmed ]

 >
 > 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
 >

Thank you, very much.  It did indeed work.

Is there a pointer to why this worked when my initial approach did not? 
  I thought from the documentation/videos that preparing a plot with 
relevant commands then issuing the show() command was the preferred 
approach within Python/Matplotlib.

JBB




--
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


Re: [Matplotlib-users] Basic matshow question

2014-07-29 Thread Eric Firing
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


[Matplotlib-users] Basic matshow question

2014-07-29 Thread JBB
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()


--
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


Re: [Matplotlib-users] graphical graph - how to

2014-07-29 Thread Oliver
The solution below is maybe not optimal, but it's something you can figure
out easily enough yourself. Also, I believe this question is better asked
on stackoverflow as it is not an actual matplotlib issue, but rather a
programming problem (that shows no effort).

Let me first redefine your matrices to comply with PEP8.

nodes = np.array([[1,2,3,4],[0, 5, 2, 8]])  # What you call Q. The first
node here is (1,0)
connections = np.triu(np.random.rand(4,4))  # What you call Z
connections[0,3] = 0  # Just to make the plot a little more clear.

for row,_ in enumerate(connections):
for col in range(row+1, connections.shape[0]):
if connections[row, col]:
plt.plot(
nodes[0,[row,col]], nodes[1,[row,col]],
color='{}'.format(connections[row, col]))  # Uses
gray-scale color-coding
plt.plot(nodes[0,:], nodes[1,:], 'ko ')


2014-07-29 14:18 GMT+02:00 Josè Luis Mietta :

> Hi experts!
>
> I have:
>
> * a list of Q 'NODES'=[(x,y)_1,, (x,y)_Q], where each element
> (x,y) represent the spatial position of the node in 2D Cartesian space.
> * a matrix 'H' with QxQ elements {H_k,l}.
> H_k,l=0 if nodes 'k' and 'l' aren't joined by a edge, and H_k,l = the length
> of the edge that connects these nodes.
> * a matrix 'Z' with QxQ elements {Z_k,l}.
> Z_k,l=0 if nodes 'k' and 'l' aren't joined by a edge, and Z_k,l =
> intensity_k,l (a intensity scale of the edge, 0 nodes are connected.
>
> I want to draw the nodes in their spatial position, connected by the
> edges, and use a color scale for the 'intensity'.
>
> How must I do that?
>
> Waiting for your answers.
>
> Thanks a lot!
>
> Best regards,
> José Luis
>
>
> --
> 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


[Matplotlib-users] graphical graph - how to

2014-07-29 Thread Josè Luis Mietta
Hi experts!

I have: 

* a list of Q 'NODES'=[(x,y)_1,, (x,y)_Q], where each element 
(x,y) represent the spatial position of the node in 2D Cartesian space.
* a matrix 'H' with QxQ elements {H_k,l}. 
H_k,l=0 if nodes 'k' and 'l' aren't joined by a edge, and H_k,l = the length of 
the edge that connects these nodes.
* a matrix 'Z' with QxQ elements {Z_k,l}. 
Z_k,l=0 if nodes 'k' and 'l' aren't joined by a edge, and Z_k,l = intensity_k,l 
(a intensity scale of the edge, 0--
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