andreasl | 4 Dec 2011 15:47
Picon

Newbie Qs regarding 3D networks

Hello,

As this is my first message here, first of all: many thanks for Mayavi. It is very impressive indeed.

I am only just starting out - got the general idea, worked through some examples. So these are proper newbie
questions. Beginning from

http://networkx.lanl.gov/examples/drawing/mayavi2_spring.html

[1] I would like to make the diameter of each graph edge (tube) depend on an associated weight value. My
impression is that tube_radius can only be a single value, not a vector, so I imagine a loop is required. Is
that correct?

[2] I am somewhat confused by the lines

   pts.mlab_source.dataset.lines = np.array(G.edges())
   tube = mlab.pipeline.tube(pts, tube_radius=0.01)

in that it is not immediately obvious that a points3d object has lines associated with it. Or are these
/created/ here (1st line)? Then how does the 2nd line 'know' that the tube shapes need to be applied to the
/lines/? Please point to relevant docs if this is explained somewhere.

[3] Would curved tubes be possible?

[4] What about arrowheads, for a directed graph?

I'm not sure how to even start approaching [3] and [4], so a general idea would be very welcome.

Thank you!

(Continue reading)

Gael Varoquaux | 6 Dec 2011 08:08
Favicon
Gravatar

Re: Newbie Qs regarding 3D networks

On Sun, Dec 04, 2011 at 03:47:33PM +0100, andreasl <at> club.lemonde.fr wrote:
> [1] I would like to make the diameter of each graph edge (tube) depend on an associated weight value. My
impression is that tube_radius can only be a single value, not a vector, so I imagine a loop is required. Is
that correct?

We can do slightly better, but it is non trivial. I posted some code to
do this recently on the enthought-dev mailing list (where many of the
Mayavi related discussions happen):
https://mail.enthought.com/pipermail/enthought-dev/2011-November/030194.html

You will need to study it and do some reading of the Mayavi documentation
on the pipeline and the difference modules to understand it.

> [2] I am somewhat confused by the lines

>    pts.mlab_source.dataset.lines = np.array(G.edges())
>    tube = mlab.pipeline.tube(pts, tube_radius=0.01)

> in that it is not immediately obvious that a points3d object has lines
> associated with it. Or are these /created/ here (1st line)?

Yes.

> Then how does the 2nd line 'know' that the tube shapes need to be
> applied to the /lines/?

Because they cannot be applied to anything else: tubes cannot be applied
to points, surfaces or volumes.

> Please point to relevant docs if this is explained somewhere.
(Continue reading)

Andreas | 20 Dec 2011 22:17
Picon

Re: Newbie Qs regarding 3D networks

Hello Gaël,

First, thanks for your answer and sorry for the delay with mine. I'm new to Python in general, and had a lot to figure out.

I used the code you linked to, with some modifications, particularly because I'm dealing with directed graphs (asymmetric adjacency matrix).

To get arrows, I made the tubes transparent and put a quiver3d on top (i.e. 'in') them:

p, li { white-space: pre-wrap; }

def plotarrows(offset):

posx = x[start_idx]

posy = y[start_idx]

posz = z[start_idx]

dirx = x[stop_idx] - posx

diry = y[stop_idx] - posy

dirz = z[stop_idx] - posz

# push the start of the arrows away from the node sphere centres

# (offset = 0.5 means they _start_ mid-way the tube)

posx = posx + offset*dirx

posy = posy + offset*diry

posz = posz + offset*dirz

arrows = mlab.quiver3d(posx, posy, posz, dirx, diry, dirz,

# sqrt() boosts smaller weights visually

scalars = np.sqrt(edge_scalar),

scale_mode = 'scalar',

scale_factor = 0.0075,

mode = 'arrow',

resolution = 6,

color = (1, 0, 0))

return arrows


That results in something like [1].

I tried to go fancy and animate the arrows, by creating three quiver3ds, at different offsets, and switching them on/off (like a traffic light):

p, li { white-space: pre-wrap; }

<at> mlab.animate(delay=10)

def anim():

ar = []

ar.append(plotarrows(0.1)); ar[0].stop()

ar.append(plotarrows(0.4)); ar[1].stop()

ar.append(plotarrows(0.7)); ar[2].stop()

while 1:

for i in [0, 1, 2]:

ar[i-1].stop()

ar[i].start()

yield


This works, but too slowly for practical use with large graphs (even when the delay is set at 10ms - the true delay is much larger on my system). I tried some alternatives: (1) using _hideshow() instead of stop() and start(); (2) creating only one quiver3d, and updating its x, y and z parameters while cycling through the three offsets, using mlab_source as explained in [2]. I didn't get a noticeable speed increase. Any alternatives for this? I haven't quite figured out the details of the pipeline system yet...

Best regards,

Andreas

[1] http://imageshack.us/photo/my-images/683/testsnapshot.png/
[2] http://github.enthought.com/mayavi/mayavi/mlab_animating.html?highlight=animating%20data

On 06/12/11 07:08, Gael Varoquaux wrote:
On Sun, Dec 04, 2011 at 03:47:33PM +0100, andreasl <at> club.lemonde.fr wrote:
[1] I would like to make the diameter of each graph edge (tube) depend on an associated weight value. My impression is that tube_radius can only be a single value, not a vector, so I imagine a loop is required. Is that correct?
We can do slightly better, but it is non trivial. I posted some code to do this recently on the enthought-dev mailing list (where many of the Mayavi related discussions happen): https://mail.enthought.com/pipermail/enthought-dev/2011-November/030194.html You will need to study it and do some reading of the Mayavi documentation on the pipeline and the difference modules to understand it.
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
MayaVi-users mailing list
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users

Gmane