Main Content

ezcontourf

(Not recommended) Easy-to-use filled contour plotter

    ezcontourf is not recommended. Use fcontour instead. For more information, see Version History.

    Description

    ezcontourf(f) plots the contour lines of the function z = f(x,y) using the contourf function. The function plots f over the default interval [-2π 2π] for x and y.

    ezcontourf automatically adds a title and axis labels.

    example

    ezcontourf(f,xyinterval) plots over the specified interval. To use the same interval for both x and y, specify xyinterval as a two-element vector of the form [min max]. To use different intervals, specify a four-element vector of the form [xmin xmax ymin ymax].

    example

    ezcontourf(___,n) plots using an n-by-n grid. Use this option after any of the input argument combinations in the previous syntaxes.

    example

    ezcontourf(ax,___) plots into the axes specified by ax instead of the current axes. Specify the axes before any of the input argument combinations in any of the previous syntaxes.

    c = ezcontourf(___) returns the contour object. Use c to modify the contour after it is created. For a list of properties, see Contour Properties.

    Examples

    collapse all

    This mathematical expression defines a function of two variables, x and y.

    f(x,y)=3(1-x)2e-x2-(y+1)2-10(x5-x3-y5)e-x2-y2-13e-(x+1)2-y2

    The ezcontourf function requires a function handle argument. Write this mathematical expression in MATLAB syntax as an anonymous function with handle f. You can define an anonymous function in the command window without creating a separate file. For convenience, write the function on three lines.

    f = @(x,y) 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
       - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
       - 1/3*exp(-(x+1).^2 - y.^2);

    Pass the function handle, f, to ezcontourf. Specify a domain from -3 to 3 in both the x-direction and y-direction and use a 49-by-49 computational grid.

    ezcontourf(f,[-3,3],49)

    Figure contains an axes object. The axes object with title 3 blank ( 1 - x ) Squared baseline blank exp (-( x Squared baseline )-( y + 1 ) Squared baseline )-...- 1 / 3 blank exp (-( x + 1 ) Squared baseline - y Squared baseline ), xlabel x, ylabel y contains an object of type contour.

    In this particular case, the title is too long to fit at the top of the graph, so MATLAB abbreviates it.

    Input Arguments

    collapse all

    Function to plot, specified as a character vector, string scalar, or function handle to a named or anonymous function.

    Specify a function of the form z = f(x,y). The function must accept two matrix input arguments and return a matrix output argument of the same size.

    When specifying the function as a character vector or string scalar, array multiplication, division, and exponentiation are always implied. For example, x^2 is interpreted as x.^2.

    Example: 'sqrt(x^2 + y^2)'

    When specifying the function as a function handle, use array operators instead of matrix operators for the best performance. For example, use .* (times) instead of * (mtimes).

    Example: @(x,y) sin(x).*cos(y)

    Plotting interval for x and y, specified in one of these forms:

    • Vector of form [min max] — Use the interval [min max] for both x and y.

    • Vector of form [xmin xmax ymin ymax] — Use the interval [xmin xmax] for x and [ymin ymax] for y.

    Size of the grid, specified as a positive integer. The grid has dimensions n-by-n.

    Axes object. If you do not specify an axes object, then the ezcontourf uses the current axes.

    Extended Capabilities

    Version History

    Introduced before R2006a

    collapse all

    R2016a: ezcontourf is not recommended

    ezcontourf is not recommended. Use fcontour instead. There are no plans to remove ezcontourf.

    fcontour requires that the input function to plot is a function handle. ezcontourf accepts either a function handle, a character vector, or a string. This table shows some typical usages of ezcontourf and how to update your code to use fcontour instead.

    Not RecommendedRecommended
    ezcontourf(@(x,y) sqrt(x.^2+y.^2))fcontour(@(x,y) sqrt(x.^2+y.^2),'Fill','on','LineColor','black')
    ezcontourf('sin(x)+cos(y)')fcontour(@(x,y) sin(x)+cos(y),'Fill','on','LineColor','black')