On Tue, Jan 31, 2012 at 12:19 AM, Christoph Piefke <
anmeld...@dunklevollnuss.de> wrote:

> Hello everybody,
>
> I have a problem transferring from 3D data to a 2D representation.
> I used mayavi to define a cut plane through a volume data set and got
> the xyz
> coordinates for the points on the plane and the data at each point.
>
> Now I would like to make a contour plot of that data in matplotlib.
>
> My first try was rotating the normal of the cut plane parallel to the
> z-axes and leaving the data unchanged.
> Unfortunately, this changed the number of grid points, so I do not know
> how to fit these both sets together.
>
> Is there a convenient way how to sample these 3d data and put it on a 2d
> grid?
>
> Thank you very much in advance, Chris
>
>
I have attached an example that was provided by a fellow user recently that
might be of use.  I am seeing how to either modify it to include it into
mplot3d or to at least include it in the gallary examples.

I hope it is helpful to you!

Ben Root
from itertools import izip
import scipy as sp
import matplotlib._cntr as cntr
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


def contour3D(x, y, z, v, levels):
    if len(levels) > 6:
        print 'Too many levels specified, should be no more than 6.'
        return
    

    # clist is the apparently impossible to find default clist for mpl
    clist = ['b','g','r','c','m','y','k']
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    for lev,color in izip(levels, clist):

        # do xy planes
        for k in xrange(0,x.shape[2]):
            c = cntr.Cntr(x[:,:,k], y[:,:,k], v[:,:,k]).trace(lev)
            for m in xrange(0, len(c)/2):
                ax.plot(c[m][:,0], c[m][:,1], z[0,0,k] * sp.ones_like(c[m][:,0]), color)

        # do xz planes
        for k in xrange(0, x.shape[1]):
            c = cntr.Cntr(x[:,k,:], z[:,k,:], v[:,k,:]).trace(lev)
            for m in xrange(0, len(c)/2):
                ax.plot(c[m][:,0], y[0,k,0] * sp.ones_like(c[m][:,0]), c[m][:,1], color)

        # do yz planes
        for k in xrange(0, x.shape[0]):
            c = cntr.Cntr(y[k,:,:], z[k,:,:], v[k,:,:]).trace(lev)
            for m in xrange(0, len(c)/2):
                ax.plot(x[k,0,0] * sp.ones_like(c[m][:,0]), c[m][:,0], c[m][:,1], color)

    plt.show()

if __name__ == "__main__":
    x,y,z = sp.mgrid[0:1:32j, 0:1:32j, 0:1:32j]
    v = sp.sqrt(x**2 + y**2 + z**2)

    contour3D(x, y, z, v, sp.r_[0.1:1:6j])


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to