English 中文(简体)
How do I generate a contour graph?
原标题:

How do I generate a contour graph like this: contour http://www.fz-juelich.de/vislab/software/gsharp/Gsharp/userguide/interpolate/ex6.gif

It s easy enough if the points are on a regular grid, but what if they aren t, like in my example? Is there a fairly simple algorithm to determine the color for each pixel?

问题回答

Maybe its a bit late,

however in the newer versions of matplotlib you can grid data:

http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data

maybe it helps

There are lots of interpolation algorithms that you can use to get intermediate points. One I have used in GIS is the Kriging algorithm, and it looks like the data you posted uses something similar. (You can tell because the "hot yellow" spots for example are not centered on the yellow sample, which would be the case with linear interpolation)

Wikipedia s Bicubic Interpolation page has some nice examples of the effect of choosing a different interpolation.

Different data may require different interpolation.

Then use Gnuplot

as described here, to create color contours.

Looks like it can handle non-rectangular data, but I would test that assumption.

An example:

Example GnuPlot contour image
(source: lanl.gov)

From here

Origin’s XYZ Contour graph lets you create a contour plot without ever having to convert your XYZ data to a matrix. It uses a form of interpolation called triangulation.

Triangulation is the division of a surface or plane polygon into a set of triangles, usually with the restriction that each triangle side is entirely shared by two adjacent triangles.Triangulation has the added benefit of being able to handle sparse, as well as irregular data.

So sounds like difficult but doable.

The image shown is not a traditional contour plot. It is essentially what matlab might produce with the function pcolor, if that function could work directly on scattered data. In fact though, pcolor is just surf, with a call to view(0,90).

If you really want to see a contour plot, the simplest answer is to use tricontour, found on the file exchange. This tool will triangulate the scattered data, then generate a contour plot.

If you wish to generate a pcolor-like solution on a scattered data set, then a simple solution is to use delaunay to triangulate the data, then call trisurf. The calls might look vaguely like this...

tri = delaunay(x,y);
trisurf(tri,x,y,z)
view(0,90)

Admittedly, that solution will not give you the nicely circular colored domain in the original picture. Other, more sophisticated solutions would be necessary for that. But since I m not sure yet whether the solution I posed above would be acceptable, I ll stop here for now.

Look up 2D interpolation. There are some simple algorithms, but they may not perform that well (or take a long time to calculate).





相关问题
c# wpf 2d graphics - Looking for tutorial / examples [closed]

Could you please point me to a good C# tutorial for drawing 2d graphics like Ellipse and Rectangle (that inherit from Shape) on a Canvas using WPF ? I m also interested later to click on shapes and ...

How to multiply two sprites in SpriteBatch Draw XNA (2D)

I am writing simple hex engine for action-rpg in XNA 3.1. I want to light ground near hero and torches just as they were lighted in Diablo II. I though the best way to do so was to calculate field-of-...

2D Ball Collisions with Corners

I m trying to write a 2D simulation of a ball that bounces off of fixed vertical and horizontal walls. Simulating collisions with the faces of the walls was pretty simple--just negate the X-velocity ...

2D Mathematics Geographical Directions

I am trying to check the location of a point(px, py) on 2D graph in relation to a line segment (lx1, ly1) (lx2, ly2), using logic of North South East West directions. The logic I have implemented is ...

Perpendicular on a line from a given point

How can I draw a perpendicular on a line segment from a given point? My line segment is defined as (x1, y1), (x2, y2), If I draw a perpendicular from a point (x3,y3) and it meets to line on point (x4,...

How to select a line

So I m trying to figure out how to implement a method of selecting lines or edges in a drawing area but my math is a bit lacking. This is what I got so far: A collection of lines, each line has two ...

How do I generate a contour graph?

How do I generate a contour graph like this: contour http://www.fz-juelich.de/vislab/software/gsharp/Gsharp/userguide/interpolate/ex6.gif It s easy enough if the points are on a regular grid, but ...

Mapping points from Euclician 2-space onto a Poincare disc

For some reason it seems that everyone writing webpages about Poincare discs is only concerned with how to represent lines and measure distances. I d like to morph a collection of 2D points (as ...

热门标签