Re: [Matplotlib-users] How can I visualize a landscape which I have sample heights of?
The mplot3d tutorial page, which is the first result when you google 'mplot3d', includes a section on 'Tri-surface plots' and is precisely what you are looking for. You certainly do not need to use scipy. Matplotlib includes its own Delaunay triangulator, as specified in the 'triangular grids' documentation, which is the first result when you google 'matplotlib triangulation'. Ian On 25 June 2015 at 12:22, Philipp A. flying-sh...@web.de wrote: hi! do a delaunay triangulation http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.Delaunay.html on them. also try to do the triangulation only on the xy coordinates and see which of both gives the results you like more. best, p justonium justinorth...@gmail.com schrieb am Do., 25. Juni 2015 um 05:21 Uhr: I have a set of three dimensional coordinates, each of which is on a landscape. I would like to visualize the entire landscape. I've already tried plotting the points in 3D space using Axes3D.scatter, but I just see a bunch of points, and it's hard to visually understand what's going on. Ideally, I would like to view a wireframe plot. In order for this to be drawn, height values will need to be interpolated from the samples that I have, which don't line up with a grid. Another solution might be: For each point, draw a vertical line from it, straight down, to a point below it which has the same x and y coordinates, with 0 as the z coordinate. This might still be difficult to visually understand. -- View this message in context: http://matplotlib.1069221.n5.nabble.com/How-can-I-visualize-a-landscape-which-I-have-sample-heights-of-tp45834.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Monitor 25 network devices or servers for free with OpManager! OpManager is web-based network management software that monitors network devices and physical virtual servers, alerts via email sms for fault. Monitor 25 devices for free with no restriction. Download now http://ad.doubleclick.net/ddm/clk/292181274;119417398;o ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Monitor 25 network devices or servers for free with OpManager! OpManager is web-based network management software that monitors network devices and physical virtual servers, alerts via email sms for fault. Monitor 25 devices for free with no restriction. Download now http://ad.doubleclick.net/ddm/clk/292181274;119417398;o ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Monitor 25 network devices or servers for free with OpManager! OpManager is web-based network management software that monitors network devices and physical virtual servers, alerts via email sms for fault. Monitor 25 devices for free with no restriction. Download now http://ad.doubleclick.net/ddm/clk/292181274;119417398;o___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to plot other than rectangular grid?
Masha, As suggested before, take a look at the triangular mesh functions. There are simple contour ( http://matplotlib.org/examples/pylab_examples/tricontour_demo.html) and pcolor plots ( http://matplotlib.org/examples/pylab_examples/tripcolor_demo.html), plus linear and cubic interpolation ( http://matplotlib.org/examples/pylab_examples/tricontour_smooth_delaunay.html and http://matplotlib.org/examples/pylab_examples/tricontour_smooth_user.html). The API documentation is at http://matplotlib.org/dev/api/tri_api.html. Ian -- Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Structure of contour object returned from tricontourf
On 2 November 2014 16:30, Benjamin Root ben.r...@ou.edu wrote: Would it make sense to at least emit a warning when a mask is encountered. There are very few places in matplotlib where masked arrays are not allowed (I think histograms is the other spot, but I can't remember for sure). Ben, That's certainly an option, but I'm happy with leaving it as it is with the onus on users to read the documentation. Ian -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Structure of contour object returned from tricontourf
On 1 November 2014 18:20, Hartmut Kaiser hartmut.kai...@gmail.com wrote: Thanks Ian! Your detailed answer is much appreciated. As you might have already guessed, we have quite some problems creating clean geometries from the generated contour data. I have tried to put together one (reasonably) small test case illustrating at least one of our issues. I apologize for the lengthy code attached. The two attached figures demonstrate what we see. Matplotlib.png (generated by the library) does not really look ok. Also, the attached shape.png shows that there are a lot of geometries generated which are self-intersecting (highlighted in dark blue), and we already skip polygons with less than 3 points. BTW, there are many polygons stacked with the same geometries. Anything we can do about this? Thanks! Regards Hartmut Hartmut, You are using masked arrays where you shouldn't, again. The documentation for tricontour states that it expects z to be an array, it doesn't say masked array. If you pass it a masked array, it will ignore the mask. Hence you have a number of triangles that include a vertex with a z-value of -9; when contoured these are going to give you lots of thin polygons that you don't want. You need to stop using masked arrays where they are not expected. Your triangulation should only contain triangles for which you have valid data at all three vertices. So either remove invalid triangles from your 'ele' array before creating the triangulation, or set a mask on the triangulation once it has been created, e.g. point_mask_indices = numpy.where(z.mask) tri_mask = numpy.any(numpy.in1d(ele, point_mask_indices).reshape(-1, 3), axis=1) triang.set_mask(tri_mask) Ian -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Structure of contour object returned from tricontourf
On 26 October 2014 00:18, Hartmut Kaiser hartmut.kai...@gmail.com wrote: At this point we assume, that polys[0] is a linear ring to be interpreted as a polygon exterior and polys[1:] are the corresponding interiors for polys[0]. Here are our questions: Is this assumption correct? Is there any detailed documentation describing the structure of the returned geometries? Are the linear rings supposed to be correctly oriented (area 0 for exteriors and area 0 for the interiors)? Hello Hartmut, In brief, the answers are no, no and yes. In more detail, assuming polys is not empty then it will contain one or more polygon exteriors and zero or more interiors, and they can be in any order. Here is a simple example where polys[0] is an interior and polys[1] an exterior: x = [0, 0, 1, 1, 0.5] y = [0, 1, 0, 1, 0.5] z = [0.5, 0.5, 0.5, 0.5, 0] triang = tri.Triangulation(x, y) contour = plt.tricontourf(triang, z, levels=[0.2, 0.4]) The returned geometries are purposefully not documented. They are an 'implementation detail' and not considered part of the public interface. and as such they could change at any time and hence should not be relied upon. Of course you can choose to access them if you wish, as I do myself sometimes, but we make no promises about what the order of the polygons is, or that it won't change tomorrow. In reality the order of the polygons is chosen to be something that is easy for both the contour generation routines to create and for the various backends to render. If you were to look at the output generated by contourf, you will see that it is organised differently from that produced by tricontourf and is more like you would like it to be, i.e. one or more groups of an exterior polygon followed by zero or more interiors. This is historical as the contourf code dates from before all of the backends were able to render arbitrary groups of exterior and interior polygons, and so the contourf code has to calculate the order for the backends. When the tricontourf code was written the backends were all able to calculate the exterior/interior containment themselves, so there was no need for tricontourf to do it as well. Ian -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Crash when using matplotlib.tri.LinearTriInterpolator
Here are the results of my investigation. There is probably more information here than anyone else wants, but it is useful information for future improvements. Most of the RAM is taken up by a trifinder object which is at the heart of a triinterpolator, and is used to find the triangles of a Triangulation in which (x,y) points lie. The code interp = tri.LinearTriInterpolator(triang, data) is equivalent to trifinder = tri.TrapezoidMapTriFinder(triang) interp = tri.LinearTriInterpolator(triang, data, trifinder=trifinder) Using the latter with memory_profiler ( https://pypi.python.org/pypi/memory_profiler) indicates that this is where most of the RAM is being used. Here are some figures for trifinder RAM usage as a function of ntri, the number of triangles in the triangulation: ntri trifinder MB 1000 26 133 10 116 100 912 21402551936 The RAM usage is less than linear in ntri, but clearly too much for large triangulations unless you have a lot of RAM. The trifinder precomputes a tree of nodes to make looking up triangles quick. Searching through 2 million triangles in an ad-hoc manner would be very slow; the trifinder is very fast in comparison. Here are some stats for the tree that trifinder uses (the columns are number of nodes in the tree, maximum node depth, and mean node depth): ntri nodes max depth mean depth --- - - -- 1000 179097 3723.24 13271933 5330.74 10 36971309 6937.15 100 853117229 8748.66 The mean depth is the mean number of nodes that have to be traversed to find a triangle, and the max depth is the worst case. The search time is therefore O(log ntri). The triangle interpolator code is structured in such a way that it is easy to plug in a different trifinder if the default one isn't appropriate. At the moment there is only the one available however (TrapezoidMapTriFinder). For the problem at hand, a trifinder that is slower but consumes less RAM would be preferable. There are various possibilities, they just have to be implemented! I will take a look at it sometime, but it probably will not be soon. Ian Thomas -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Crash when using matplotlib.tri.LinearTriInterpolator
On 10 August 2014 18:43, Hartmut Kaiser hartmut.kai...@gmail.com wrote: All, I'm running into a crash while trying to construct a tri.LinearTriInterpolator. Here is the short version of the code: import netCDF4 import matplotlib.tri as tri var = netCDF4.Dataset('filename.cdf').variables x = var['x'][:] y = var['y'][:] data = var['attrname'][:] elems = var['element'][:,:]-1 triang = tri.Triangulation(x, y, triangles=elems) # this crashes the python interpreter interp = tri.LinearTriInterpolator(triang, data) The data arrays (x, y, data, elems) are fairly large (1 mio elements), all represented as numpy arrays (as returned by netCDF4). The 'data' array is a masked array and contains masked values. If somebody cares, I'd be able to post a link to the netCDF data file causing this. All this happens when using matplotlib 1.3.1, Win32, Python 2.7. Any help would be highly appreciated! Regards Hartmut Hartmut, That is an excellent issue report; all the relevant information and nothing extraneous. Hence the quick response. The second argument to TriLinearInterpolator (and other TriInterpolator classes), i.e. your 'data' array, is expected to be an array of the same size as the 'x' and 'y' arrays. It is not expecting a masked array. If a masked array is used the mask will be ignored, and so the values behind the mask will be used as though they were real values. If my memory of netCDF is correct, this will be whatever 'FillValue' is defined for the file, but it may depend on what is used to generate the netCDF file. I would normally expect the code to work but produce useless output. A crash is possible though. It would be best if you could post a link to the netCDF file and I will take a closer look to check there is not something else going wrong. Ian Thomas -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bug in contourf or BoundaryNorm?
On 28 March 2014 12:56, Jesper Larsen jesper.webm...@gmail.com wrote: I believe the normalization behaviour is wrong for contourf at least when using a BoundaryNorm. In the script below I am using the same norm to plot the same data using contourf and pcolormesh. The color should change around an x value of 0.15 but it is shifted somewhat for contourf. I do realize that the pcolormesh is in principle shifted a little - but with a grid spacing of 0.001 that should not matter. Please see the example script below. Best regards, Jesper Test inconsistent normalization behaviour for matplotlib import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import from_levels_and_colors # Make custom colormap and norm levs = [0.0, 0.1, 0.2] cols = [[0.00392156862745098, 0.23137254901960785, 0.07450980392156863], [0.00392156862745098, 0.49019607843137253, 0.15294117647058825]] extend = 'neither' cmap, norm = from_levels_and_colors(levs, cols, extend) # Setup testdata a = np.arange(0.05, 0.15, 0.001, dtype=np.float_) a, b = np.meshgrid(a, a)0 plt.contourf(a, b, a, norm=norm, cmap=cmap, antialiased=False) plt.savefig('contourf.png') plt.clf() plt.pcolormesh(a, b, a, norm=norm, cmap=cmap, antialiased=False) plt.savefig('pcolormesh.png') Jesper, Regardless of whether you specify a colormap and norm, if you want contourf to calculate contours at particular levels then you need to specify those levels. If you don't then contourf will choose the levels for you, and in your case these are chosen to be [0.045 0.06 0.075 0.09 0.105 0.12 0.135 0.15 ] which is why you see the color transition at x=0.105. To fix this, change your contourf line from plt.contourf(a, b, a, norm=norm, cmap=cmap, antialiased=False) to plt.contourf(a, b, a, norm=norm, cmap=cmap, antialiased=False, levels=levs) and you will get exactly what you want. Ian -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Plotting NOAA grib2 data in basemap
On 29 January 2014 03:21, Eric Firing efir...@hawaii.edu wrote: On 2014/01/28 10:01 AM, A Short wrote: Hi - Ive now improved my code and confirmed the use of the right grib file but i cant for the life of me figure out the missing data near the coastline..? Could anyone help? The present contouring algorithm works with rectangular blocks, and if any corner has missing data, nothing is filled for that block. This will improve shortly, cutting off the corners of some of those empty blocks. I am currently testing the new algorithm for this prior to submitting it for others' approval. Ian -- WatchGuard Dimension instantly turns raw network data into actionable security intelligence. It gives you real-time visual feedback on key security issues and trends. Skip the complicated setup - simply import a virtual appliance and go from zero to informed in seconds. http://pubads.g.doubleclick.net/gampad/clk?id=123612991iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Limiting interpolation of map plot with tricontourf
On 1 November 2013 13:55, Jule rik...@gmx.de wrote: Hey guys, I have a question regarding my plot. http://matplotlib.1069221.n5.nabble.com/file/n42446/seaice.png I want to plot seaice thickness distribution. The data is derived from a model run using an unstructured grid. To plot data on a map I use Triangulation and tricontourf. The problem I´m facing now is, that due to the triangulation my data is interpolated, resulting in an ocean covered by a thin layer of sea ice everywehere, which is unrealistic! So my question is, is there a way to limit the interpolation to the maximum extend of my data? I did a plot with MATLAB just to let you know how it should look like. http://matplotlib.1069221.n5.nabble.com/file/n42446/ice_thick_N.jpg My code looks like this so far: triang = tri.Triangulation(x,y) fig = plt.figure() plt.tricontourf(triang, ee, levels = levs, extend = 'both') cbar=plt.colorbar(orientation = 'horizontal', ticks=[0, 1, 2, 3, 4]) cbar.set_label('Seaice thickness [m]', size=20,fontname='Arial') fc=map.fillcontinents(color = 'grey') Since I´m a beginner I would really appreciate any thoughts and suggestions! Thanks! Try the following two changes, they should give you what you want. 1) Don't use extend='both' in your tricontourf call. This is explicitly asking for all areas below 0 (your lowest level) to be coloured dark blue. Use extend='max' instead to ignore areas that are below your lowest level. 2) Change your lowest level. It looks like you are using levs=[0.0, 0.5, 1.0, etc. The lowest levels that are contoured are therefore where z = 0.0 and z 0.5. This obviously includes all your non-sea ice areas as they have z = 0.0. Change your first value in levs to be something slightly greater than zero, e.g. 1e-10. By the way, your question is slightly confusing as you talk about interpolation, which has nothing to do with what you are seeing! Ian -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Build failure
On 26 October 2013 09:02, Nils Wagner nils...@googlemail.com wrote: The problem persists in master. On Fri, Aug 30, 2013 at 7:39 PM, Nils Wagner nils...@googlemail.comwrote: You are right. The first one fails, the second works for me. Nils On Fri, Aug 30, 2013 at 7:20 PM, Michael Droettboom md...@stsci.eduwrote: I wonder if it's commit 6b827cbf. Can you do: git checkout 6b827cbf python setup.py build # confirm it fails git checkout 6b827cbf^ python setup.py build # Does this work? Mike On 08/30/2013 01:06 PM, Nils Wagner wrote: Hi Michael, Thank you for your note. If I remember correctly I was able to build matplotlib a week ago. I am using opensuse12.3 Nils rpm -qi python-cxx Name: python-cxx Version : 6.2.3 Release : 2.2 Architecture: noarch Install Date: Sa 27 Jul 2013 15:48:45 CEST Group : Development/Languages/Python Size: 9783 License : GPL Signature : RSA/SHA1, Mo 22 Jul 2013 20:26:22 CEST, Key ID 45a1d0671abd1afb Source RPM : python-cxx-6.2.3-2.2.src.rpm Build Date : Mo 22 Jul 2013 15:27:08 CEST Build Host : swkj07 Relocations : (not relocatable) Packager: pack...@links2linux.de Vendor : http://packman.links2linux.de URL : http://CXX.sourceforge.net/ Summary : Write Python extensions in C++ Description : PyCXX is a set of classes to help create extensions of Python in the C language. The first part encapsulates the Python C API taking care of exceptions and ref counting. The second part supports the building of Python extension modules in C++. Distribution: Extra / openSUSE_12.3 On Fri, Aug 30, 2013 at 6:46 PM, Michael Droettboom md...@stsci.eduwrote: It looks like a version mismatch with PyCXX. Was it recently updated or changed? What version of PyCXX do you have? What was the last version of matplotlib that worked for you? You can force matplotlib to use its local copy of PyCXX by uninstalling PyCXX, or adding the following lines to the top of PyCXX::check in setupext.py: self.__class__.found_external = False return Couldn't import. Using local copy. (But really, we should update setupext so users can specify the local override in setup.cfg). Mike On 08/30/2013 12:35 PM, Nils Wagner wrote: Hi all, I cannot build the latest matplotlib from git. The build log is attached. Nils I have had a quick look at this and it seems the problem lies in setupext.py. CXX.check() contains return self._check_for_pkg_config('PyCXX', 'CXX/Extensions.hxx', min_version='6.2.4') which requires version 6.2.4 or later of CXX. Nils has 6.2.3 and so this check should fail and matplotlib should fall back to using the local copy of CXX. SetupPackage._check_for_pkg_config() does check min_version if CXX is installed using pkg-config, but if it is not then min_version is ignored as the function raises a CheckFailed error before min_version is considered. CXX.check() catches this error and uses the system-installed CXX regardless of its version. To check the CXX version we probably need to look in CXX/Version.hxx. I am not sure how to proceed; do you have any ideas Mike? Nils, as a stopgap you could either remove your python-cxx and python-cxx-devel rpms if you don't need them for anything else, or upgrade them to 6.2.4. There is a 6.2.4 on rpm.pbone.net even though there isn't one on packman.links2linux.de. Ian -- October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60135991iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] bisecting triangulation
On 1 July 2013 13:40, zetah ot...@hush.ai wrote: Hi, I have set of points in a plane and make triplot: subplot(121) plot(points[:,0], points[:,1], 'o') title('Set of points') subplot(122) triplot(points[:,0], points[:,1]) title('Triangulation') result: http://i.imgur.com/1LG4fxC.png Does anyone know how to extract just the lines describing each circumscribed circle in this example? Perhaps by using Delaunay from scipy.spatial? Just to inform you, I want to do this through triangulation and above example is trivial that can be solved differently, while real problem doesn't contain circles... You need to use a matplotlib.tri.Triangulation (your use of triplot does this for you behind the scenes anyway), something like: import matplotlib.tri as mtri triang = mtri.Triangulation(xpoints, ypoints) Now triang.triangles is an array of integers of shape (?, 3) such that triang.triangles[i,:] are the three indices of the points that comprise triangle i. You will need to use these to determine the information you want. The triplot example ( http://matplotlib.org/examples/pylab_examples/triplot_demo.html) does something similar, identifying which triangles are within a particular circle; I guess in your case a simple approach would be to test if the distance from the centre of each triangle edge to your circle of interest is below some threshold or not. Incidentally, if you have a Triangulation object then subsequent calls to functions like triplot can be of the form triplot(triang), which will be faster than repeated calls to triplot(xpoints, ypoints) as in the latter case a separate Delaunay triangulation needs to be performed for each triplot call. Ian -- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata fails
On 9 January 2013 09:32, Shahar Shani-Kadmiel kadm...@post.bgu.ac.ilwrote: Hi, I'm trying to contour some data that I have and the griddata line fails. I tried running it on some synthetically generated data and I get the same IndexError. Any Ideas? Here is the example with the synthetic data: x = y = arange(-10,10,0.01) z = x**2+y**3 xi = yi = linspace(-10.1, 10.1, 100) zi = griddata(x, y, z, xi, yi) --- IndexErrorTraceback (most recent call last) ipython-input-52-0458ab6ea672 in module() 1 zi = griddata(x, y, z, xi, yi) /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/mlab.py in griddata(x, y, z, xi, yi, interp) 2766 xi,yi = np.meshgrid(xi,yi) 2767 # triangulate data - 2768 tri = delaunay.Triangulation(x,y) Hello Shahar, I think that your simple example is probably not what you intended. Your (x,y) points are all defined on the straight line from (-10,-10) to (10,10). The Delaunay triangulation of these points (which is what griddata does) is not very interesting! Perhaps you wanted (x,y) defined on the 2D grid from (-10,-10) to (10,10), in which case you should follow the x = y ... line with, for example: x, y = meshgrid(x, y) (see numpy.meshgrid for further details). You may still obtain the same IndexError, and the traceback shows this is happening in the delaunay.Triangulation function call. The matplotlib delaunay package is not particularly robust, and can have problems handling regularly-spaced data points. The griddata documentation explains some of this, see http://matplotlib.org/api/mlab_api.html#matplotlib.mlab.griddata. To avoid the problem, the griddata documentation explains one possible way that uses the natgrid algorithm. A simpler solution that I often use is to add a very small amount of noise to my regularly-spaced (x,y) points using the numpy.random module. I can give more details if you wish. Ian -- Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Gap when using contourf and nan's
On 16 November 2012 15:38, Bror Jonsson brorl...@gmail.com wrote: Oh, I left out a line in the code, very sorry for that. Here is a full example: import numpy as np import pylab as pl #Generate a matrix populated with 1's fld = np.ones((4,4)) #Set one corner of the matrix to NaN fld[:2,:2] = np.nan #Plot the contourf plot of the matrix pl.contourf(arange(4),arange(4),fld,colors='b') #Create a mask where the NaN's are reversed. mask = np.isnan(fld).astype(np.float) mask[mask==0] = np.nan #Plot the contourf of the mask contourf(arange(4),arange(4),mask,colors='r') The cells with values in mask covers the cells with nan's in fld exactly: In [102]: print fld Out[102]: array([[ nan, nan, 1., 1.], [ nan, nan, 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.]]) In [101]: print mask Out[101]: array([[ 1., 1., nan, nan], [ 1., 1., nan, nan], [ nan, nan, nan, nan], [ nan, nan, nan, nan]]) There are, however, a gap between the red and the blue areas in the figure. Is there a way to make contourf plot mask so that the red patch extends to 2,2 and covers all cells with 1's in mask? Many thanks! :-)Bror Bror, The key to understanding this behaviour is to realise that your fld and mask values are defined at grid points, whereas contour deals with the quads that connect these grid points. If a single grid point is masked out, all 4 quads that the point is a corner of are masked out as far as contour is concerned as you cannot contour a quad that doesn't have all 4 points defined. You could solve your problem using contour but you would have to expand the mask so that each masked point [j,i] was expanded to [j-1:j+1, i-1:i+1]. I cannot think of a cunning numpy way of doing this whilst handling all the edge cases and would have to resort to explicit looping over the indices. There is a better way. From the point mask create a quad mask which is one smaller in each direction. Then use pcolor rather than contour as pcolor takes a quad-centric view of the world. Also, when dealing with masks I use numpy.ma rather than having to handle NaNs. Here is the simplest modification of your code that I can come up with to do what you want: import numpy as np import pylab as pl #Generate a matrix populated with 1's fld = np.ones((4,4)) #Set one corner of the matrix to NaN fld[:2,:2] = np.nan #Create a mask. mask = np.isnan(fld) #Expand mask so that it is a quad mask. mask = 1 - (mask[:-1,:-1] | mask[:-1,1:] | mask[1:,:-1] | mask[1:,1:]) #Create masked array. maskedArray = np.ma.array(np.zeros_like(mask), mask=mask) #Note mask is one smaller than fld in each direction. print 'fld.shape', fld.shape, 'mask.shape', mask.shape pl.contourf(np.arange(4), np.arange(4), fld, colors='b') #pcolor does what you want. Any colormap is chosen that has red as its first color. pl.pcolor(np.arange(4), np.arange(4), maskedArray, cmap='autumn') pl.show() Ian -- Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Gap when using contourf and nan's
On 14 November 2012 21:05, Bror Jonsson brorl...@gmail.com wrote: Dear all, I'm trying to to show where one set of values have NaN's on the contour plot of another set of values. I do this by creating a mask as such: fld = randn(4,4) fld[:2,:2] = np.nan mask[mask==0] = np.nan contourf(arange(4),arange(4),fld) contourf(arange(4),arange(4),mask) The problem is that the mask patch doesn't cover the empty space in the fld contour. Is there any way to make this happen? My ultimate goal is something like this: fld2 = randn(4,4) contourf(arange(4),arange(4),fld2) contourf(arange(4),arange(4),mask,[1,1], extend='both', colors='w', alpha=0.5) to present where fld has NaN's on the fld2 plot. Many thanks in advance! Bror Jonsson Hello Bror, It is not clear from your code snippets exactly what you are asking for. Please can you post a full runnable example? Ian Thomas -- Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Clipping Contours
On 16 October 2012 18:44, T J tjhn...@gmail.com wrote: This is a set of 152 points on a triangle. delaunay is mentioned to have problems for some pathological cases. Is a complete triangular grid considered as such a case? Yes, under certain circumstances! delaunay is not 'geometrically robust', meaning it doesn't take into account machine precision errors when deciding if a point is on one side of a line or not or inside a circle or not, which can result in errors leading to the algorithm failing. It sounds like this should be an easy problem to solve but it isn't. In your example the y-values that presumably should be in a straight line about y=-0.5 feature variations at about the 16th decimal place that are causing the algorithm to fail. If these variations were much larger or much smaller, the algorithm would probably work. The first time the failure occurs is at the 20th point, which you can see if you add a call to something like plt.tripcolor(x, y, np.zeros_like(x), alpha=0.5) The darker blue colour shows two triangles overlapping, which shouldn't happen. You have a number of options: 1) Round your x and y values to a smaller number of decimal places, e.g. x = x.round(8) y = y.round(8) On my machine 8 decimal places is good, 10 isn't. 2) Add extra noise to your point positions, which is the classic way to get around this delaunay limitation, e.g. x = x + 1e-6*np.random.rand(len(x)) y = y + 1e-6*np.random.rand(len(x)) 3) Specify the triangulation yourself, which is usually pretty easy for regular cases like yours. See tricontour_demo.py for an example of how to specify a triangulation in your tri* function calls. I hope this helps, Ian -- Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_sfd2d_oct___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] [matplotlib-devel] Bug in Triangulation causes infinite loop if 4 or more duplicate points are used in tricontour()
On 16 April 2012 23:36, Damon McDougall d.mcdoug...@warwick.ac.uk wrote: On Monday, 16 April 2012 at 16:34, Kacper Kowalik wrote: On 16 Apr 2012 22:31, Damon McDougall d.mcdoug...@warwick.ac.uk wrote: Hi Kacper, Just to be clear, is it tri.Triangulation(x, y) that hangs, or is it plt.tricontour(…)? It's plt.tricontour that hangs, tri.Triangulation properly issues warning about duplicates. Cheers, Kacper On Monday, 16 April 2012 at 14:28, Kacper Kowalik wrote: Hi, I haven't been able to pin point it exactly but following script: import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np from numpy.random import uniform, seed seed(0) npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) z = x*np.exp(-x**2-y**2) y[1:3] = x[0] # 4 or more duplicate points make tricontour hang!!! x[1:3] = y[0] You should call z = x*np.exp(-x**2-y**2) _before_ changing the points you're triangulating. Having said that, I see the same behaviour even if I change the vertices before I compute z. triang = tri.Triangulation(x, y) plt.tricontour(x, y, z, 15, linewidths=0.5, colors='k') plt.show() causes infinite loop in _tri.so. It happens in matplotlib-1.1.0 as well as git HEAD. I understand that my input is not exactly valid, but I'd rather see MPL die than occupy my box for eternity ;) Best regards, Kacper I think the reason it's hanging is because you're trying to plot the contours of a function that is defined on an invalid triangulation (edges cross at points that are not in the vertex set). I think the best way to deal with this is to write a helper function to check the triangulation is valid. If it isn't, either tri.Triangulation(x, y) should fail, or the plotter should fail. Anybody else have any suggestions? We can definitely do better here. I have created a issue request on github: https://github.com/matplotlib/matplotlib/issues/838 and will investigate further. Ian -- Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Hardware rendering with tricontourf
On 26 January 2012 19:36, Howard how...@renci.org wrote: I'm rendering some images with about 3.5 million triangles into a 512x512 png file using tricontourf. I'm running this in a virtual machine, and I'm pretty sure that there is no graphics rendering hardware being used. Is it possible, assuming the hardware was available, to make tricontourf use the rendering hardware? Will that happen by default? You are correct, there is no graphics hardware rendering. Rendering is controlled by the various matplotlib backends, and to my knowledge there are no backends currently available that use hardware rendering. There has been some work done on an OpenGL backend, but I am not sure of the status of this. The last time I checked it was pretty experimental. Perhaps someone involved with it can comment on its current status. Ian Thomas -- Try before you buy = See our experts in action! 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-dev2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Triangulations and Polar Plots
On 15 November 2011 00:18, Daniel Welling dantwell...@gmail.com wrote: Greetings. I recently found myself in the position of needing to plot polar, irregularly spaced data. I've done similar using regularly spaced values with no problem. However, I've found that when the points become greatly scattered, the triangulation does not translate from rectangular to polar very well. Below, find a code example that shows this; though it is much better than my real-world case that uses simulation results. Essentially, in the translation from regular to polar axes, many of the triangles overlap others, many features of the plot are lost, and the plot looks mangled in certain regions, esp. across the theta=0 boundary. While subtle here (but MUCH worse in the results I'm trying to visualize), some of the triangles lie outside of the triangulated region. It isn't merely that the polar plot is suffering from poor data coverage; the triangulation is not working properly in polar coordinates and the results are quantitatively different than the rectangular plot. The obvious work-around for this problem illustrates the issue more clearly. If we convert rad, theta back to x, y and do a rectangular plot, the triangulation is much better (not only is there no issue around theta=0, but there are no overlapping triangles), all of the details of the non-polar version are maintained, and the plot looks great. This is not the best solution, as polar plots in Matplotlib are quite elegant. Any help here would be appreciated. It could be that triangulations are just not suited for polar plots; it could be that the theta=0 issue throws things off, etc; I'm just not sure. It would be perfect if I could use the polar axes in the end. Thanks. -dw Daniel, I can't give you much help but I can provide some explanation. If you don't specify a triangulation of your own, the matplotlib tri* functions use lib/matplotlib/delaunay/triangulate as a black box. You are right in saying that it is not suited to polar plots; it assumes cartesian axes. The lib/matplotlib/tri/* functions use triangulations that comprise a number of triangles with vertices ordered in an anticlockwise manner. The delaunay triangulation returns such triangles on a cartesian grid. But if you transform a cartesian triangulation to a polar grid, you invariably end up with some triangles which are ordered clockwise and hence also overlap each other. Tricontour doesn't like this and gives the best results it can given that is has been passed an incorrect triangulation, which from your point of view means the wrong results. In addition, as you have noticed there are other problems around theta=0. In a polar plot points near theta=0 are visible both from the low and high theta ends of the plot, whereas in a cartesian plot they are only visible from one side unless you take steps to repeat such points so the wraparound works. The answer, unfortunately, is to specify your own triangulation using the 'triangles' keyword in your calls to the tri* functions. I suspect that most people who regularly use the tri* functions obtain their triangulations from elsewhere rather than using the matplotlib delaunay code. It should be possible to pass your polar coordinates to delaunay to obtain the triangulation in polar space, then use this triangulation in your tri* polar plots. However, I've tried it (albeit briefly) and it appears to hang the delaunay code. An alternative may be to take a look at griddata (there is an example in matplotlib's pylab_examples directory). It is difficult for me to recommend such an approach, however, as I wrote the tri* functions so that I wouldn't have to use griddata! Ian -- RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Triangulation objects
On 13 November 2011 19:10, Daniel Welling dantwell...@gmail.com wrote: I am interested in accessing Triangulation objections that are created by MPL for tricontour-type plots. The docs for MPL routines that use triangulation objects refer to documentation, but none exists in the MPL online docs. Does anyone have docs/info on using these objects? Having access to them would be great. The easiest way to find out about Triangulation objects is to look at the source code on github: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tri/triangulation.py The class and __init__ descriptions should contain all the information you need. Ian -- RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Inner boundaries in tricontourf
On 30 August 2011 18:23, Tijs de Kler tijs.dek...@sara.nl wrote: Im trying to use the tricontourf function in matplotlib to reduce the complexity of an unstructured dataset into contours. The resulting contours are retrieved from the path by the to_polygon() function, but i have some trouble distinguishing inner boundaries on the polygons, while plot.show() clearly doesn't Using Matplotlib 1.01, and the attached code, I get one level, consisting of 2 polygons, where the first is the outer boundary, and the second should be the inner boundary. The figure shown by show() correctly displays a square with a inner square cut-out. However i cannot distinguish between inner and outer boundaries in the list of polygons that to_polygon() returns. Is there a trick how the plot functions distinguish inner boundaries? Calculating for each polygon if it is contained in other polygons will become complicated with a large number of polygons: As far as i can tell this would be checking if the starting point of each polygon is contained in any of the other polygons. Is there a simpler method i missed? Matplotlib includes a function to determine if a set of points is within a polygon, called points_inside_poly. For an example see http://matplotlib.sourceforge.net/faq/howto_faq.html#test-whether-a-point-is-inside-a-polygon That is about as simple as it gets from a user's perspective! Since you ask about tricks in plot functions, no there aren't any. Rendering functions don't explicitly determine if a contour polygon is an inner or outer boundary. Usually a sweep algorithm is performed across all points to construct the triangulation of the polygons as it progresses. You could extract the inner/outer-ness of each boundary from such an algorithm but it would be overkill for what you want to do. Ian Thomas -- Special Offer -- Download ArcSight Logger for FREE! Finally, a world-class log management solution at an even better price-free! And you'll get a free Love Thy Logs t-shirt when you download Logger. Secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsisghtdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Inner boundaries in tricontourf
I forgot to mention the obvious solution! Outer boundaries are ordered anticlockwise, inner boundaries clockwise. Calculate the area of each boundary assuming it is ordered anticlockwise, and if the area is positive it is an outer boundary, if negative it is an inner boundary. I've attached a modified version of your debug.py to show this. This may be simpler to use than points_inside_poly, but if you have multiple nested boundaries it could get confusing unless you know which boundary encloses which others. Ian Thomas import matplotlib import matplotlib.pyplot as plot import numpy as np def get_polygon_area(vertices): v2 = np.roll(vertices, -1, axis=0) return np.cross(vertices, v2).sum() / 2.0 def is_polygon_inner_boundary(vertices): return get_polygon_area(vertices) 0.0 x_array = [] y_array = [] for i in range(1,5) : for j in range(1,5) : x_array.append(i) y_array.append(j) triang = [ [0,4,5],[0,5,1], [1,5,6],[1,6,2], [2,6,7], [2,7,3],[4,8,9], [4,9,5], [6,10,11],[6,11,7], [8,12,13], [8,13,9],[9,13,14], [9,14,10], [10,14,15],[10,15,11]] triangle_poly =matplotlib.tri.Triangulation(x_array, y_array, triang) data=[1]*16 level_list = [0,2] contourplot = plot.tricontourf(triangle_poly, data, level_list) for level in contourplot.collections: polys = level.get_paths()[0].to_polygons() for poly in polys: print 'polygon:', poly print 'inner boundary:', is_polygon_inner_boundary(poly) plot.show() -- Special Offer -- Download ArcSight Logger for FREE! Finally, a world-class log management solution at an even better price-free! And you'll get a free Love Thy Logs t-shirt when you download Logger. Secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsisghtdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Change color for fill_between to contour plot
Try tricontourf; I've attached an example. Most of the example code is manipulating your input data and calculating the connectivity of your grid. I hope this helps, Ian Thomas import matplotlib.pyplot as plt import numpy as np x,y1,y2,y3,y4,stress = np.loadtxt('data.txt', skiprows=2, delimiter=',', unpack=True) # Arrays of all the point coordinates and stresses. n = len(x) x = np.hstack((x,x,x,x)) y = np.hstack((y1,y2,y3,y4)) stress = np.hstack((stress,stress,stress,stress)) # Triangle connectivity. triangles = [] for i in range(n-1): triangles.append([i,i+1,n+i]) triangles.append([i+1,n+i+1,n+i]) triangles.append([2*n+i,2*n+i+1,3*n+i]) triangles.append([2*n+i+1,3*n+i+1,3*n+i]) # Plot. plt.tricontourf(x, y, triangles, stress) plt.colorbar() plt.show() attachment: test.png-- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Boundary edges of a set of points
On 28 April 2011 22:56, Luke hazelnu...@gmail.com wrote: I am thinking that perhaps the approach I should be taking should involve contouring the real part of the eigenvalues which determine the stability, and then plot the zero-level curve. I'll have to think about that some more. This sounds like a very sensible approach and is quick and easy to try out using tricontour/tricontourf. You may have to use a very small positive value for the contour level rather then zero to get what you want. Is it clear what I am trying to do? If so, do you think the Delaunay triangulation is the right way to go? Yes, it is clear what you are trying to do. I think that you shouldn't be concerned with the triangulation, Delaunay or not, as this is at too low a level for what you are attempting. Stick to the high-level data analysis and presentation functions like tricontour and ignore details of the underlying triangulation. If you are having to manipulate a triangulation then you are becoming a computational geometrist - it is a completely valid and interesting thing to do but is probably taking your attention away from your real work. Ian -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Boundary edges of a set of points
On 28 April 2011 08:51, Luke hazelnu...@gmail.com wrote: I have a set of unstructured (x,y) points which I would like to compute a boundary polygon for. I don't want the convex hull. I was able to use matplotlib.tri to get a Delaunay triangulation for my points by following the examples online, but I'm having trouble masking everything but the triangles with a boundary edge. Additionally, once I get this, I'm not clear on how to plot just the boundary. Here is what it seems like the mask should be, assume triang comes from matplotlib.tri.Triangulation(). mask = np.where(np.where(triang.neighbors 0, 0, 1).all(axis=1), 1, 0) triang.set_mask(mask) but, when I plot triang using plot.triplot(), or plt.plot() to plot the edges, I am getting a bunch of extra stuff that isn't just the boundary triangles/edges. Anybody have example code for properly masking and plotting only the boundary edges? ~Luke Luke, I am not entirely clear exactly what you want to do, but I'll try to help. Your masking of the triangulation masks the triangles not the edges, and so your triplot call displays those triangles that include a boundary edge but also the other edges of those triangles. As you say, this isn't what you want. I've attached an example script that follows on from your idea of testing triang.neighbors to determine the boundary edges, and displays just those edges. However, this is the convex hull as, by definition, the boundary of an unconstrained Delaunay triangulation is the convex hull. As you don't want the convex hull, I am not clear what you want instead. If I have misunderstood your requirements and/or you have further questions, please post your example code as it is much easier for others on the mailing list to correct existing code than come up with their own freestanding example. I hope some of this helps! Ian Thomas import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np # Create triangulation of random (x,y) points. np.random.seed(0) x = np.random.rand(10) y = np.random.rand(10) triang = tri.Triangulation(x, y) # Determine which triangulation edges are boundary edges; these # correspond to edges that have no neighboring triangle. Store them as # pairs of (start,end) point indices. # This is all calculated long-hand to demonstrate the logic. It could # be simplified by rewriting in a more pythonic way. boundaries = [] for i in range(len(triang.triangles)): for j in range(3): if triang.neighbors[i,j] 0: # Triangle edge (i,j) has no neighbor so is a boundary edge. boundaries.append((triang.triangles[i,j], triang.triangles[i,(j+1)%3])) boundaries = np.asarray(boundaries) # The following line plots the boundary edges. plt.plot(x[boundaries].T, y[boundaries].T, 'b-') plt.plot(x, y, 'bo') plt.show() -- WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] pyplot: Extract contourset without plotting
Daniel, Following on from Eric's comments, attached is the simplest example I could come up with to do what you want. For non-filled contours, the 'segs' (last few lines of the file) should be fairly self-explanatory, and this is hopefully what you want. If you are after filled contours, you will need to understand both the 'segs' and the 'kinds' - essentially the segs comprise one or more discontinuous closed line loops and the corresponding kinds indicate how the loops are split up, a 1 being a LINETO and a 2 being a MOVETO. This can get a little awkward, and I think that sometimes you need to deal with arrays of arrays but I can't completely remember all the details. You should bear in mind that this code delves into matplotlib internals and you need to be careful as 1) it bypasses various sanity checks, 2) the underlying code could change at any point in the future (it has quite a lot in the last year for example). Otherwise, I hope it helps! Ian import matplotlib._cntr as cntr import numpy as np import numpy.ma as ma # Make your choice of filled contours or contour lines here. wantFilledContours = True # Test data. x = np.arange(0, 10, 1) y = np.arange(0, 10, 1) x, y = np.meshgrid(x, y) z = np.sin(x) + np.cos(y) z = ma.asarray(z, dtype=np.float64) # Import if want filled contours. if wantFilledContours: lower_level = 0.5 upper_level = 0.8 c = cntr.Cntr(x, y, z.filled()) nlist = c.trace(lower_level, upper_level, 0) nseg = len(nlist)//2 segs = nlist[:nseg] kinds = nlist[nseg:] print segs# x,y coords of contour points. print kinds # kind codes: 1 = LINETO, 2 = MOVETO, etc. # See lib/matplotlib/path.py for details. else: # Non-filled contours (lines only). level = 0.5 c = cntr.Cntr(x, y, z) nlist = c.trace(level, level, 0) segs = nlist[:len(nlist)//2] print segs# x,y coords of contour points. -- Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] mplot3d - ploting 3d triangular mesh model - need help
On 11 November 2010 12:41, isolat illoul_am...@yahoo.fr wrote: hi all, please is there any one can tell me if it's possible in mplot3d to plot 3d triangular mesh model with a colormap different from the Z variable. I don't find example in tutorial for this. thanks. No, this is not possible. Support for triangular mesh functions in mplot3d is currently very limited. Ian -- Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Problems using triplot from file
On 27 September 2010 15:37, radfahrer clem...@m-info.de wrote: I am trying to plot a triangular grid from a textfile using triplot, but all I get is some wired straight line Your triangulation consists of just two triangles, the first with vertices (0, 0) (0.1, 0.1) (0.1, 0.1) and the second (0, 0), (0.1, 0.1), (0, 0). Each of these triangles has duplicate vertices and is therefore a straight line. In fact you only have three distinct points in your points.dat file, at (0, 0), (0.05, 0.05), and (0.1, 0.1). You can never construct a triangle which isn't a straight line with these points. Perhaps you intended your points.dat file to be something like 0 0 0 0.05 0 0.1 0.05 0 0.05 0.05 0.05 0.1 0.1 0 0.1 0.05 0.1 0.1 Ian -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Plotting 3D, Irregularly Triangulated Surfaces - An Example
On 17 September 2010 16:26, Simon S. Clift sscl...@gmail.com wrote: I have a data set that is in the form of an irregular 2D grid with associated values, one for each node. I would like to plot this as a raised surface, with colours that indicate the z-value. Somehow I didn't find just quite the example I was looking for. After digging around in the matplotlib and mpl_toolkits.mplot3d I was able to solve the problem. To save the next person the trouble, here is my annotated example. Comments and improvements are most welcome. I'd be happy to have a version of this included as an official example, if it passes muster. Thanks for this. The tripcolor function does what you want in 2D, but it hasn't yet been extended to work with 3D axes. It was on my 'to do' list, and you've motivated me to start looking at it. When it's done, your example code can be much simpler as the triangulation and colormap manipulation will all be done for you. Ian -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] contour's polygons
On 28 July 2010 01:31, Phil Rosenfield philr...@astro.washington.eduwrote: I'd like to use the polygons contour makes but I can't figure out how to get them from ContourSet. Any examples or links to helpful information would be excellent. Attached is an example of how to extract the polygons from a ContourSet. import matplotlib.pyplot as plt import numpy as np # Dummy x,y,z data. x = np.linspace(0, 1, 10) y = np.linspace(0, 1, 10) x,y = np.meshgrid(x,y) z = np.sin(7*x)*np.sin(7*y) # Contours levels. levels = [0, 0.4, 0.8] nlevels = len(levels) # Use either one of the following two lines: contourset = plt.contour(x, y, z, levels)# Line contours #contourset = plt.contourf(x, y, z, levels) # Filled contours # contourset.collections is a list of nlevels LineCollections if using contour # and a list of (nlevels-1) PathCollections if using contourf. print contourset.collections # Look at a single level index. If you want all of the contour levels, you # will need to loop through them. level = 1 print 'level is', levels[level] paths = contourset.collections[level].get_paths() npaths = len(paths) print 'number of paths', npaths for i in range(npaths): path = paths[i] print 'path', i, 'of', npaths # Each path has vertices, it may also have codes. If codes is None, the # vertices are a single continuous path of line segments and should be easy # to deal with. If codes is not None then vertices is probably 2 or more # discontinuous line segments; you will need to understand the codes for # MOVETO and LINETO at least - see lib/matplotlib/path.py for details. print ' codes', path.codes print ' vertices', path.vertices # Show the contour plot to help explanation. plt.colorbar() plt.show() -- The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details: http://p.sf.net/sfu/dev2dev-palm___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Contour Plotting of Varied Data on a Shape
Chris Barker wrote: hmm -- I wonder if a post to matplotlib-devel is in order. Most of those folks are on this list, to, but may not be following this thread. I'll post to matplotlib-devel shortly and see what response I get. By the way, it sounds like your contouring code is in C++ -- is that important? Yes, it is C++ and it is important - that's what I've got and hence that's what I'm offering! Portability should be fine as I'm only using some of the basic STL containers which are already used by, for example, the matplotlib delaunay code. Ian -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Contour Plotting of Varied Data on a Shape
Chris Barker wrote: ... snip ... To summarise, you recommend the following units of functionality: 1) Triangulation class to wrap existing delaunay code. 2) Separate the storage of and creation of contour sets so that you can create your own. 3) tricontour and tricontourf functions to contour a Triangulation. 4) Python utility plotting functions for a Triangulation (triplot, tripcolor, etc). 5) Simple wrappers for 3 and 4 so you can just pass in the points and the Triangulation is created for you behind the scenes. I am happy to make a start with this; no doubt it will take me a while. I should point out that I don't intend to tinker with the delaunay code, so we'll still be left with those pathological cases that it doesn't work with. Maybe this can be revisited when I'm done. Do you want it all in one go, or one unit of functionality at a time (my preference)? Thanks for this, I'm hope I'm not alone in thinking it's really useful stuff. Let's see! I'll hold off starting until there have been some votes for it from other people. Ian -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Contour Plotting of Varied Data on a Shape
Chris Barker wrote: I think it would be great to have in MPL. What code are you using for the triangulation? Does it do constrained delauney? My code only does the contouring; you have to input the triangulation. In the examples included with the code I used matplotlib.delaunay to do the triangulations so as not to reinvent the wheel. To include it in MPL, I would need to improve it somewhat (there are a couple of known bugs and insufficient documentation) and there would need to be a discussion of the API. At the moment I am using tricontour(x, y, triangulation_indices, z, optional_mask) followed by the usual contour args (N or V) and kwargs. Is this OK? I've also written utility plotting functions triplot, trifill and tripcolor; are these wanted? In terms of implementation, at the python level I have a TriContourSet class which is the same as the existing ContourSet apart from a few lines that deal with input arguments and calling the appropriate underlying C++ code. Ideally it would be sensible to refactor the common python code into a new class (BaseContourSet?) and have relatively thin derived ContourSet and TriContourSet classes. But I'm not sure you'd like a relatively new mpl contributor to change such important code... Ian -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Contour Plotting of Varied Data on a Shape
Hello all, I submitted some code to matplotlib-users last September to perform contouring of triangular grids. The posts and code can be found at: http://sourceforge.net/mailarchive/forum.php?thread_name=4AB3B95B.3090903%40noaa.govforum_name=matplotlib-users Like I wrote at the time, if it is useful to enough people I'm happy to improve the code provided it can be incorporated into mpl as I have no interest in maintaining it as a standalone project. Ian On 8 March 2010 23:33, gely g...@usc.edu wrote: Christopher Barker wrote: gely wrote: As I think about it, I'm going to have to write code to do this (contour an unstructured triangular mesh) sometime soon, so please let me know if it does exist already -- if not I'll try to remember to contribute it when I get around to it. -Chris Chris, I found this old thread. Did you ever find code to directly interpolate a triangulation? sorry, no, not yet. Do you already have the triangulation? if so, it's pretty easy to contour. Thanks for the reply. Yes. I have the triangulation as a list of point coordinates and a list of triangles with indices to the points. Good to know it's not difficult. I'll have to chew on this for a bit. -Geoff -- View this message in context: http://old.nabble.com/Contour-Plotting-of-Varied-Data-on-a-Shape-tp25089018p27829342.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Contouring on triangular grids
I've written some code to perform contouring on triangular grids. I wrote the underlying C++ for a separate project, but as there has been some interest on the mpl mailing lists for such functionality I've had a go at wrapping it up as a python module so that it is available from mpl. I've also added a few utility functions for plotting triangular grids, doing pseudocolour plots, etc. Attached is the source code with some documentation and examples. There's an example of the output at http://img10.imageshack.us/img10/2873/tricontourfdemo3g.png This example is similar to one of the mpl contourf examples, but on a triangular grid of 1000 randomly spaced points, with the grid overlaid. So far it is only experimental code and hasn't been widely tested. I have a list of improvements already, but thought it best to let people see a working version before spending time polishing it. If it turned out that a (much improved) version of it was considered good enough to incorporate into mpl, I'd would happily help as I'd like to contribute. I hope someone finds it useful! Ian Thomas mpl_tri.tar.gz Description: GNU Zip compressed data -- Come build with us! The BlackBerryreg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9#45;12, 2009. Register now#33; http://p.sf.net/sfu/devconf___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users