Main Content


(Not recommended) Easy-to-use contour plotter

    ezcontour is not recommended. Use fcontour instead. For more information, see Compatibility Considerations.



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

    ezcontour automatically adds a title and axis labels to the plot.


    ezcontour(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].


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

    ezcontour(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 = ezcontour(___) returns the contour object. Use c to modify the contour after it is created. For a list of properties, see Contour Properties.


    collapse all

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


    The ezcontour 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 ezcontour. Specify a domain from -3 to 3 in both the x-direction and y-direction and use a 49-by-49 computational grid.


    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 ezcontour uses the current axes.

    Extended Capabilities

    Version History

    Introduced before R2006a

    collapse all

    R2016a: ezcontour is not recommended

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

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

    Not RecommendedRecommended
    ezcontour(@(x,y) sqrt(x.^2+y.^2))fcontour(@(x,y) sqrt(x.^2+y.^2))
    ezcontour('sin(x)+cos(y)')fcontour(@(x,y) sin(x)+cos(y))