On Fri, May 22, 2009 at 7:06 AM, John Hunter <jdh2...@gmail.com> wrote: > On Thu, May 21, 2009 at 9:31 PM, Ondrej Certik <ond...@certik.cz> wrote: >> Hi, >> >> I have a set of vertices in 2D as triples (x, y, val), where the x, y >> are 2D coordinates and "val" is the scalar value of the finite element >> solution, here is an example: >> >> In [54]: l.get_vertices() >> Out[54]: >> array([[ 0.00000000e+00, -1.00000000e+00, -2.22396971e-17], >> [ 1.00000000e+00, -1.00000000e+00, -1.64798730e-17], >> [ -1.00000000e+00, 0.00000000e+00, 8.09899023e-17], >> ..., >> [ 1.48437500e-01, -1.56250000e-02, 1.62359362e-01], >> [ 1.32812500e-01, 0.00000000e+00, 1.56012622e-01], >> [ 1.32812500e-01, -1.56250000e-02, 1.50562411e-01]]) >> >> >> and I also have a set of triangles that connect those points, here is >> an example: >> >> In [55]: l.get_triangles() >> Out[55]: >> array([[ 3, 5448, 29], >> [ 27, 5445, 28], >> [ 29, 28, 26], >> ..., >> [5499, 5498, 5479], >> [5510, 5493, 5491], >> [5513, 5508, 5491]], dtype=int32) >> >> >> The triangles define the 2D domain. What is the best way to get this >> plotted with mpl? Should I write a loop using the "plot" command, or >> is there a better alternative? So far, I am using the contour command >> and I feed it just with the vertices, here is the code: > > The best way is to define your triangles as an n length list of > triangle vertices > > verts = [ ( (x00, y00), (x01, y01), (x02, y02)), > (x10, y10), (x11, y11), (x12, y12)), > ... > ] > > and have an equal length array of intensities for color mapping. > > vals = np.array(N_color_intensities) > > Then create a PolyCollection: > > import matplotlib.cm as cm > import matplotlib.collections as collections > col = collections.PolyCollection(verts) > col.set_array(val) > col.set_cmap(cm.hot) > ax.add_collection(col) > > add_collection doesn't get the autoscaling limits, if I recall > correctly, so you will probably want to do > > ax.set_xlim(xmin, xmax) > ax.set_ylim(ymin,. ymax) > > See also: > > http://matplotlib.sourceforge.net/api/collections_api.html#matplotlib.collections.PolyCollection > http://matplotlib.sourceforge.net/search.html?q=codex+PolyCollection > > > Unfortunately, we do not currently have support for interpolating > between adjacent polys in a PolyCollection, so the result may not look > as nice as mayavis.
Thanks a lot John. I tried that and it does what I want. I just need to convert and probably average my 3 different values at the 3 vertices of the triangle and color the triangle with that color. When I get it working, I'll send you a picture. :) On Fri, May 22, 2009 at 7:32 AM, Eric Carlson <ecarl...@eng.ua.edu> wrote: > Here is an example using matplotlib.delaunay, which automatically > returns the edges and triangules: Thanks, that works too -- but it only plots the edges, right? I will use that to plot the mesh, I need that as well. For the FE solution, I'll use John's approach. Ondrej ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users