Accelerating the pace of engineering and science

# pdeplot

Plot solution

## Description

example

pdeplot(p,e,t) plots the (p,e,t) mesh.

example

pdeplot(p,e,t,Name,Value) plots data on the (p,e,t) mesh using one or more Name,Value pair arguments.

Give at least one of the flowdata (vector field plot), xydata (colored surface plot), or zdata (3-D height plot) name-value pairs. Otherwise, pdeplot plots the mesh with no data. You can combine any number of plot types.

example

h = pdeplot(___) returns handles to the axis objects using any of the input arguments in the previous syntaxes.

## Examples

expand all

### Mesh Plot

Plot the p,e,t mesh.

Create the geometry and mesh.

```[p,e,t] = initmesh('lshapeg');
```

Plot the mesh.

```pdeplot(p,e,t)
```

### 2-D Solution Plot

Plot a PDE solution as a 2-D colored surface plot.

Create the geometry, mesh, boundary conditions, PDE coefficients, and solution.

```[p,e,t] = initmesh('lshapeg');
u = assempde('lshapeb',p,e,t,1,0,1);
```

Plot the solution.

```pdeplot(p,e,t,'xydata',u)
```

### 3-D Solution Plot

Plot a PDE solution as a 3-D colored plot.

Create the geometry, mesh, boundary conditions, PDE coefficients, and solution.

```[p,e,t] = initmesh('lshapeg');
u = assempde('lshapeb',p,e,t,1,0,1);
```

Plot the solution.

```pdeplot(p,e,t,'xydata',u,'zdata',u)
```

### Solution Quiver Plot

Plot the gradient of a PDE solution as a quiver plot.

Create the geometry, mesh, boundary conditions, PDE coefficients, and solution.

```[p,e,t] = initmesh('lshapeg');
u = assempde('lshapeb',p,e,t,1,0,1);
```

Calculate the gradient of the solution. Put the gradient in a matrix for inclusion in the quiver plot.

```[ux,uy] = pdegrad(p,t,u); % Calculate gradient
```

Plot the gradient as a quiver plot.

```pdeplot(p,e,t,'flowdata',ugrad)
```

### Composite Plot

Plot the solution of a PDE in 3-D with the 'jet' coloring and a mesh, and include a quiver plot. Get handles to the axis objects.

Create the geometry, mesh, boundary conditions, PDE coefficients, and solution.

```[p,e,t] = initmesh('lshapeg');
u = assempde('lshapeb',p,e,t,1,0,1);
```

Calculate the gradient of the solution. Put the gradient in a matrix for inclusion in the quiver plot.

```[ux,uy] = pdegrad(p,t,u); % Calculate gradient
```

Plot the solution in 3-D with the 'jet' coloring and a mesh, and include the gradient as a quiver plot.

```h = pdeplot(p,e,t,'xydata',u,'zdata',u,...
```
```h =

3x1 graphics array:

Patch
Quiver
ColorBar

```

Look underneath to see the quiver plot.

```view(20,-20)
```

## Input Arguments

expand all

### p — Mesh pointsmatrix

2-by-Np matrix of points, where Np is the number of points in the mesh. For a description of the (p,e,t) matrices, see Mesh Data.

Typically, you use the p, e, and t data exported from the PDE app, or generated by initmesh or refinemesh.

Example: [p,e,t] = initmesh(gd)

Data Types: double

### e — Mesh edgesmatrix

7-by-Ne matrix of edges, where Ne is the number of edges in the mesh. For a description of the (p,e,t) matrices, see Mesh Data.

Typically, you use the p, e, and t data exported from the PDE app, or generated by initmesh or refinemesh.

Example: [p,e,t] = initmesh(gd)

Data Types: double

### t — Mesh trianglesmatrix

4-by-Nt matrix of triangles, where Nt is the number of triangles in the mesh. For a description of the (p,e,t) matrices, see Mesh Data.

Typically, you use the p, e, and t data exported from the PDE app, or generated by initmesh or refinemesh.

Example: [p,e,t] = initmesh(gd)

Data Types: double

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: pdeplot(p,e,t,'xydata',u,'zdata',u) sets surface plot coloring to the solution u, and sets the heights for a 3-D plot to the solution u.
 Tip   Give at least one of the flowdata (vector field plot), xydata (colored surface plot), or zdata (3-D height plot) name-value pairs. Otherwise, pdeplot plots the mesh with no data.

### 'colorbar' — Indicator to include color bar'on' (default) | 'off'

Indicator to include color bar, specified as the comma-separated pair consisting of 'colorbar' and a string. 'on' displays a bar giving the numeric values of colors in the plot. For details, see colorbar. pdeplot uses the colormap specified in the colormap name-value pair.

Example: 'colorbar','off'

Data Types: char

### 'colormap' — Colormap'cool' (default) | colormap string or matrix

Colormap, specified as the comma-separated pair consisting of 'colormap' and a string representing a built-in colormap, or a colormap matrix. For details, see colormap.

colormap relates to the xydata name-value pair.

Example: 'colormap','jet'

Data Types: double | char

### 'contour' — Indicator to plot level curves'off' (default) | 'on'

Indicator to plot level curves, specified as the comma-separated pair consisting of 'contour' and a string. 'on' plots level curves for the xydata data. Specify the levels with the levels name-value pair.

Example: 'contour','on'

Data Types: char

### 'flowdata' — Data for quiver plotmatrix

Data for quiver plot, specified as the comma-separated pair consisting of 'flowdata' and a matrix of vector data. flowdata can be M-by-2 or 2-by-M, where M is the number of mesh points p or the number of triangles t. flowdata contains the x and y values of the field at the mesh points or at the triangle centroids.

Typically, you set flowdata to the gradient of the solution. For example:

```[ux,uy] = pdegrad(p,t,u); % Calculate gradient

In a 3-D plot, the quiver plot appears in the z = 0 plane.

pdeplot plots the real part of complex data.

Data Types: double

### 'flowstyle' — Indicator to show quiver plot'arrow' (default) | 'off'

Indicator to show quiver plot, specified as the comma-separated pair consisting of 'flowstyle' and a string. 'arrow'displays the quiver plot specified by the flowdata name-value pair.

Example: 'flowstyle','off'

Data Types: char

### 'gridparam' — Customized grid for xygrid name-value pair[tn;a2;a3] from an earlier call to tri2grid

Customized grid for the xygrid name-value pair, specified as the comma-separated pair consisting of 'gridparam' and the matrix [tn;a2;a3]. For example:

```[~,tn,a2,a3] = tri2grid(p,t,u,x,y);
pdeplot(p,e,t,'xygrid','on','gridparam',[tn;a2;a3],'xydata',u)```

For details on the grid data and its x and y arguments, see tri2grid.

Example: 'gridparam',[tn;a2;a3]

Data Types: double

### 'levels' — Levels for contour plot10 (default) | positive integer | vector of level values

Levels for contour plot, specified as the comma-separated pair consisting of 'levels' and a positive integer or a vector.

• Positive integer — Plot levels equally-spaced contours.

• Vector — Plot contours at the values in levels.

To obtain a contour plot, set the contour name-value pair to 'on'.

Example: 'levels',16

Data Types: double

### 'mesh' — Indicator to show mesh'off' (default) | 'on'

Indicator to show mesh, specified as the comma-separated pair consisting of 'mesh' and a string. 'on' shows the mesh in the plot.

Example: 'mesh','on'

Data Types: char

### 'title' — Title of plotstring

Title of plot, specified as the comma-separated pair consisting of 'title' and a string.

Example: 'title','Solution Plot'

Data Types: char

### 'xydata' — Colored surface plot datavector

Colored surface plot data, specified as the comma-separated pair consisting of 'xydata' and a vector. Give data for points in a vector of length size(p,2), or data for triangles in a vector of length size(t,2).

Typically, you set xydata to u, the solution. pdeplot uses xydata for coloring both 2-D and 3-D plots.

pdeplot uses the colormap specified in the colormap name-value pair, using the style specified in the xystyle name-value pair.

When the contour name-value pair is 'on', pdeplot also plots level curves of xydata.

pdeplot plots the real part of complex data.

To plot the kth component of a solution to a PDE system, extract the relevant part of the solution. For example:

```np = size(p,2); % number of node points
uk = reshape(u,np,[]); % each uk column has one component of u
pdeplot(p,e,t,'xydata',uk(:,k)) % data for column k```

Example: 'xydata',u

Data Types: double

### 'xygrid' — Indicator to convert to x-y grid before plotting'off' (default) | 'on'

Indicator to convert mesh data to x-y grid before plotting, specified as the comma-separated pair consisting of 'xygrid' and a string.

 Note:   This conversion can change the geometry, and can lessen the quality of the plot.

By default, the grid has about sqrt(size(t,2)) elements in each direction. Exercise more control over the x-y grid by generating it with the tri2grid function, and passing it in with the gridparam name-value pair.

Example: 'xygrid','on'

Data Types: char

### 'xystyle' — Coloring choice'interp' (default) | 'off' | 'flat'

Coloring choice, specified as the comma-separated pair consisting of 'xystyle' and a string.

• 'off' — No shading, shows the mesh only.

• 'flat' — Each triangle in the mesh has a uniform color.

• 'interp' — Plot coloring is smoothly interpolated.

The coloring choice relates to the xydata name-value pair.

Example: 'xystyle','flat'

Data Types: char

### 'zdata' — Data for 3-D plot heightsmatrix

Data for 3-D plot heights, specified as the comma-separated pair consisting of 'zdata' and a vector. Give data for points in a vector of length size(p,2), or data for triangles in a vector of length size(t,2).

Typically, you set zdata to u, the solution. The xydata name-value pair sets the coloring of the 3-D plot. The zstyle name-value pair specifies whether the plot is continuous or discontinuous.

pdeplot plots the real part of complex data.

To plot the kth component of a solution to a PDE system, extract the relevant part of the solution. For example:

```np = size(p,2); % number of node points
uk = reshape(u,np,[]); % each uk column has one component of u
pdeplot(p,e,t,'xydata',uk(:,k),'zdata',uk(:,k)) % data for column k```

Example: 'zdata',u

Data Types: double

### 'zstyle' — 3-D plot style'continuous' (default) | 'off' | 'discontinuous'

3-D plot style, specified as the comma-separated pair consisting of 'zstyle' and a string.

• 'off' — No 3-D plot.

• 'discontinuous' — Each triangle in the mesh has a uniform height in a 3-D plot.

• 'continuous' — 3-D surface plot is continuous.

zstyle relates to the zdata name-value pair.

Example: 'zstyle','discontinuous'

Data Types: char

## Output Arguments

expand all

### h — Handles to axis objects in the plotvector of handles

Handles to axis objects in the plot, returned as a vector.