levels, a MATLAB code which draws a contour plot of a function, using sampling to determine the appropriate contour levels.
MATLAB's contour() function displays a contour plot of a data, described either as a table Z(X,Y), or as a function F(X,Y). (From here on, we'll assume that the functional description is being used.) The user can specify the number of contour levels, and can also specify the values of the contour levels, but it is common to let MATLAB handle this task with default settings.
But for some functions, the evenly spaced contour levels, from FMIN to FMAX, will not do a good job of showing the "shape" of the data. This typically happens where there are some extreme, localized values of the function, or when a large area of the region has roughly the same value. In such cases, the contour lines will cluster around a small area of rapid variation, and ignore the rest of the region.
LEVELS offers a simple solution. It simply samples the data at a random number of points and uses those values as the contour levels. The reason this helps is that this procedure will tend to use more contour lines exactly in those ranges that occur more often. If a large area has roughly the same value, then there will be many more contour levels used to try to discriminate the behavior in that area.
LEVELS_XY is appropriate when the variables X and Y are treated separately.
levels_xy ( @f, level_num, x_range, y_range )where
function z = f(x,y)
The computer code and data files described and made available on this web page are distributed under the MIT license
levels is available in a MATLAB version.
dist_plot, a MATLAB code which makes contour plots of the distance function, as defined and used in Persson and Strang's distmesh code;
hypersphere_surface, a MATLAB code which illustrates a procedure for estimating the location of a hypersurface defined by a characteristic function or a signed function.
surf_test, a MATLAB code which demonstrates the MATLAB surf() function for displaying a 3D surface of the form Z=F(X,Y).
triangulation_order3_contour, a MATLAB code which makes contour plot of scattered data, or of data defined on an order 3 triangulation.
triangulation_order6_contour, a MATLAB code which makes contour plots of data defined on an order 6 triangulation.