How do I generate a contour graph like this:
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?
How do I generate a contour graph like this:
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?
Look up 2D interpolation. There are some simple algorithms, but they may not perform that well (or take a long time to calculate).
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.
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)
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:
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.