ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 29 Jul 2014 12:24:48 -0500- Draw a 2D spatial networkhttps://ask.sagemath.org/question/23623/draw-a-2d-spatial-network/ 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)
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Ã© LuisTue, 29 Jul 2014 07:21:54 -0500https://ask.sagemath.org/question/23623/draw-a-2d-spatial-network/
- Answer by niles for <p>Hi experts!</p>
<p>I have:</p>
<ul>
<li>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.</li>
<li>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.</li>
<li>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)</li>
</ul>
<p>I want to draw the nodes in their spatial position, connected by the edges, and use a color scale for the 'intensity'.</p>
<p>How must I do that?</p>
<p>Waiting for your answers.</p>
<p>Thanks a lot!</p>
<p>Best regards,
JosÃ© Luis</p>
https://ask.sagemath.org/question/23623/draw-a-2d-spatial-network/?answer=23626#post-id-23626The commands [point2d](http://www.sagemath.org/doc/reference/plotting/sage/plot/point.html#sage.plot.point.point2d) and [line](http://www.sagemath.org/doc/reference/plotting/sage/plot/line.html#sage.plot.line.line) will draw points and lines for you. Here is an example:
nodes = [(1,1),(-1,1),(2,0)]
points = point2d(nodes,color='black',size=50)
lines = line((nodes[0],nodes[1]),hue=.2) + line((nodes[0],nodes[2]),hue=.4)
(points + lines).show(axes=False)
You could write a loop over the elements of the matrix 'Z' which adds the relevant line if the intensity is not zero, and uses the intensity value for the hue.
Tue, 29 Jul 2014 12:24:48 -0500https://ask.sagemath.org/question/23623/draw-a-2d-spatial-network/?answer=23626#post-id-23626