1 function p = plot_vertex_data(grid,data,params)
2 %
function p = plot_vertex_data(grid,data[, params])
3 % plot method
for vertex data on a 2D polygonal grid.
5 % For example a `P1` functions routine can be used
for triangular and
6 % rectangular grids. A patch plot is performed as
default. In
case of
7 % rectangular elements, no
true bilinear interpolation is performed, but the
8 % patch is divided into triangles.
11 % data: a vector of length
'grid.nvertices' with nodewise scalar values.
12 % params: optional structure holding fields controlling the plot output.
15 % p: This is the list of handles to the graphics primitives
17 % optional fields of params:
18 % shrink_factor :
if this flag is given, the elements are plotted shrinked
19 % axis_equal :
if this flag is set, set axis to equal scale
20 % no_lines :
if this flag is set, no lines are drawn
21 % show_colorbar :
if this flag is set, a colorbar is drawn (
default 1)
22 % colorbar_location :
string specifying the position of the
23 % colorbar, e.g.
'South',
'EastOutside' (
default), etc.
24 % clim :
if this 2-vector is set, the colorbar is set to
27 % Bernard Haasdonk 9.5.2007
33 if ~(isfield(params,
'shrink_factor'))
34 params.shrink_factor = 1.0;
37 if ~(isfield(params,
'axis_equal'))
38 params.axis_equal = 0;
41 if ~(isfield(params,
'no_lines'))
45 if ~(isfield(params,
'show_colorbar'))
46 params.show_colorbar = 1;
49 if ~(isfield(params,
'colorbar_location'))
50 params.colorbar_location =
'EastOutside';
53 if (length(data)~=grid.nvertices)
54 error(
'length of data does not match number of elements!');
59 % compute vertex coordinates and scale
60 XX = grid.X(grid.VI(:));
61 XX = reshape(XX,size(grid.VI)); % nelements*nneigh matrix
62 YY = grid.Y(grid.VI(:));
63 YY = reshape(YY,size(grid.VI)); % nelements*nneigh matrix
65 CXX = repmat(grid.CX(:),1,nneigh);
66 CYY = repmat(grid.CY(:),1,nneigh);
69 XX = (XX - CXX) *params.shrink_factor + CXX;
70 YY = (YY - CYY) *params.shrink_factor + CYY;
73 CC = data(grid.VI(:));
74 CC = reshape(CC,size(grid.VI)); % nelements*nneigh matrix
76 if isfield(params,
'plot_mode') && isequal(params.plot_mode,
'3d')
77 p = patch(XX',YY',CC',CC');
78 if isfield(params, 'view')
84 p = patch(XX',YY',CC');
96 set(p,'linestyle','none');
99 if params.show_colorbar
100 if isfield(params,'clim')
101 set(gca,'Clim',params.clim)
103 colorbar(params.colorbar_location);