surfht
Interactive contour plot
Syntax
Description
Examples
Create Interactive Contour Plot
This example shows how to use surfht
to create an interactive contour plot.
Create a grid of the (x,y) domain from (–2,–2) to (2,2) using meshgrid
.
[x,y] = meshgrid(-2:0.2:2,-2:0.2:2);
Evaluate the function over this domain.
z = x.*exp(-x.^2 - y.^2);
Open an interactive contour plot. Because meshgrid
creates a grid of the x and y values, open the plot using the first row of x and the first column of y.
surfht(x(1,:),y(:,1),z)
The figure shows a contour plot of the z values along the specified x- and y-axes.
Click the plot to evaluate z at the (x,y) coordinates indicated by the intersecting lines.
For example, at x = 0.71041 and y = 0.025723, the value of z is 0.41827.
Alternatively, enter values in the fields labeled X Value
and Y Value
to evaluate z at the specified coordinates. For example, evaluate z at x = 0.5 and y = 1.
The value of z is 0.1397.
Input Arguments
z
— z-axis values for contour plot
numeric matrix
z-axis values for contour plot, specified as a numeric matrix.
surfht
treats the values in z
as
the height above the plane. By default, the x-axis
values of the plot are the column indices of z
,
and the y-axis values of the plot are the row indices
of z
. To change the x- and y-axis
values, specify x
and y
,
respectively.
Data Types: single
| double
x
— x-axis values for contour plot
column indices of z
(default) | numeric vector
x-axis values for contour plot, specified
as a numeric vector. The length of x
must match
the number of columns in z
.
Data Types: single
| double
y
— y-axis values for contour plot
row indices of z
(default) | numeric vector
y-axis values for contour plot, specified
as a numeric vector. The length of y
must match
the number of rows in z
.
Data Types: single
| double
Tips
The intersection of the vertical and horizontal reference lines on the interactive plot defines the current x value and y value.
Drag the reference lines to watch the interpolated z value (at the top of the plot) update simultaneously.
Alternatively, obtain a specific interpolated z value by typing the x value and y value into editable text fields on the x-axis and y-axis, respectively.
Version History
Introduced before R2006aR2024b: Plot uses default background
The surfht
function uses the default background instead of
always setting the background to black.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)