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:

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

@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, andre...@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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users

Reply via email to