Plotting streamlines on 3D surface with Mayavi

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting streamlines on 3D surface with Mayavi

Nikolaus Rath
Hello,

I'd like to plot stream lines on a three dimensional surface. Currently
I'm using mesh + quiver, but this doesn't look nice because the arrows
stick out of the plane and aren't connected.

Example:

import numpy as np
(ys, xs) = np.mgrid[-10:10:50j, -10:10:50j]
zs = np.cos(xs/2) + 0.5 * np.cos(ys/4)
alpha = np.arctan2(ys, xs)
u = np.sin(alpha)
v = -np.cos(alpha)
w = -u * np.sin(xs/2)/2 - v * np.sin(ys/4)/4

# 3D, but ugly
from mayavi import mlab
mlab.mesh(xs, ys, zs)
mlab.quiver3d(xs, ys, zs, u, v, w)

# 2D, but nice
import matplotlib.pyplot as plt
plt.streamplot(xs, ys, u, v)



Based on some examples I have found, I believe that what I want is the
Mayavi streamline module. But I wasn't able to find any documentation
for this at all.

Does anyone have a pointer for me?


It'd be especially nice if there was a way to specify the surface
connectivity explicitly (like in mlab.triangular_mesh).


Best,
-Nikolaus
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Plotting streamlines on 3D surface with Mayavi

Gael Varoquaux
On Wed, Jan 23, 2013 at 03:27:12PM -0800, Nikolaus Rath wrote:
> Based on some examples I have found, I believe that what I want is the
> Mayavi streamline module. But I wasn't able to find any documentation
> for this at all.

Streamlines are done with the 'mlab.flow' function. However, it won't
restrict the lines to a surface. It is documented as all the other
functions:
http://docs.enthought.com/mayavi/mayavi/mlab.html#id1
http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#flow

You may also find interesting:
http://docs.enthought.com/mayavi/mayavi/mlab.html#visualizing-a-vector-field

and examples:
http://docs.enthought.com/mayavi/mayavi/auto/example_lorenz.html#example-lorenz
http://docs.enthought.com/mayavi/mayavi/auto/example_magnetic_field_lines.html#example-magnetic-field-lines

HTH,

Gael
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Plotting streamlines on 3D surface with Mayavi

Nikolaus Rath
Gael Varoquaux <[hidden email]> writes:

> On Wed, Jan 23, 2013 at 03:27:12PM -0800, Nikolaus Rath wrote:
>> Based on some examples I have found, I believe that what I want is the
>> Mayavi streamline module. But I wasn't able to find any documentation
>> for this at all.
>
> Streamlines are done with the 'mlab.flow' function. However, it won't
> restrict the lines to a surface. It is documented as all the other
> functions:
> http://docs.enthought.com/mayavi/mayavi/mlab.html#id1
> http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#flow

Yeah, I actually looked at that function. But the documentation says
that flow plots a "vector field described by three 3D arrays". What I
have is a vector field on a surface, not in a volume, so my arrays are 2D.
I guess I could add a third dimension of length 1, but then my grid will
still not be homogenously spaced in 3d space. Is there a way to use
flow() even in that situation?
 
> You may also find interesting:
> http://docs.enthought.com/mayavi/mayavi/mlab.html#visualizing-a-vector-field
>
> and examples:
> http://docs.enthought.com/mayavi/mayavi/auto/example_lorenz.html#example-lorenz
> http://docs.enthought.com/mayavi/mayavi/auto/example_magnetic_field_lines.html#example-magnetic-field-lines

This is exactly what I meant with no documentation at all :-). While the
resulting graphic looks really nice, I don't know what e.g.

# Plot the flow of trajectories with suitable parameters.
f = mlab.flow(x, y, z, u, v, w, line_width=3, colormap='Paired')
f.module_manager.scalar_lut_manager.reverse_lut = True
f.stream_tracer.integration_direction = 'both'
f.stream_tracer.maximum_propagation = 200

or

field_lines = mlab.pipeline.streamline(magnitude, seedtype='line',
                                        integration_direction='both',
                                        colormap='bone',
                                        vmin=0, vmax=1)

# Tweak a bit the streamline.
field_lines.stream_tracer.maximum_propagation = 100.
field_lines.seed.widget.point1 = [69, 75.5, 75.5]
field_lines.seed.widget.point2 = [82, 75.5, 75.5]
field_lines.seed.widget.resolution = 50
field_lines.seed.widget.enabled = False

means. How do I determine what parameters and tweaks are suitable for my
use case?


Best,

   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Plotting streamlines on 3D surface with Mayavi

Gael Varoquaux
On Fri, Jan 25, 2013 at 06:19:36PM -0800, Nikolaus Rath wrote:
> Yeah, I actually looked at that function. But the documentation says
> that flow plots a "vector field described by three 3D arrays". What I
> have is a vector field on a surface, not in a volume, so my arrays are 2D.
> I guess I could add a third dimension of length 1,

That's what I would do.

> but then my grid will still not be homogenously spaced in 3d space. Is
> there a way to use flow() even in that situation?

I don't know. The interpolation of the field or the integration might
break in a too thin sheet of data.

You'll have to find out by yourself, everybody has different usecases and
leads to different usage patterns.

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev