Skip to Main Content Skip to Search
Product Documentation

ezplot - Easy-to-use function plotter

Example of ezplot function output

Syntax

ezplot(fun)
ezplot(fun,[xmin,xmax])
ezplot(fun2)
ezplot(fun2,[xymin,xymax])
ezplot(fun2,[xmin,xmax,ymin,ymax])
ezplot(funx,funy)
ezplot(funx,funy,[tmin,tmax])
ezplot(...,figure_handle)
ezplot(axes_handle,...)
h = ezplot(...)

Description

ezplot(fun) plots the expression fun(x) over the default domain -2π < x < 2π, where fun(x) is an explicit function of only x.

fun can be a function handle or a string.

ezplot(fun,[xmin,xmax]) plots fun(x) over the domain: xmin < x < xmax.

For an implicit function, fun2(x,y):

ezplot(fun2) plots fun2(x,y) = 0 over the default domain -2π < x < 2π, -2π < y < 2π.

ezplot(fun2,[xymin,xymax]) plots fun2(x,y) = 0 over xymin < x < xymax and xymin < y < xymax.

ezplot(fun2,[xmin,xmax,ymin,ymax]) plots fun2(x,y) = 0 over xmin < x < xmax and ymin < y < ymax.

ezplot(funx,funy) plots the parametrically defined planar curve funx(t) and funy(t) over the default domain 0 < t < 2π.

ezplot(funx,funy,[tmin,tmax]) plots funx(t) and funy(t) over tmin < t < tmax.

ezplot(...,figure_handle) plots the given function over the specified domain in the figure window identified by the handle figure.

ezplot(axes_handle,...) plots into the axes with handle axes_handle instead of the current axes (gca).

h = ezplot(...) returns the handle to all the plot objects in h.

Tips

Passing the Function as a String

Array multiplication, division, and exponentiation are always implied in the expression you pass to ezplot. For example, the MATLAB syntax for a plot of the expression

x.^2 - y.^2

which represents an implicitly defined function, is written as

ezplot('x^2 - y^2')

That is, x^2 is interpreted as x.^2 in the string you pass to ezplot.

Passing a Function Handle

Function handle arguments must point to functions that use MATLAB syntax. For example, the following statements define an anonymous function and pass the function handle fh to ezplot,

fh = @(x,y) sqrt(x.^2 + y.^2 - 1);
ezplot(fh)
axis equal

which plots a circle. Note that when using function handles, you must use the array power, array multiplication, and array division operators (.^, .*, ./) since ezplot does not alter the syntax, as in the case with string inputs.

Passing Additional Arguments

If your function has additional parameters, for example k in myfun:

function z = myfun(x,y,k)
z = x.^k - y.^k - 1;

then you can use an anonymous function to specify that parameter:

ezplot(@(x,y)myfun(x,y,2))

Controlling Line Color

ezplot colors lines according to the type of graphics object it chooses to plot the input function.

Example

Plotting an Explicit Function

This example plots an explicit function:

x2 

over the domain [-2π, 2π].

h = ezplot('x^2')
set(h, 'Color', 'm');			% Make the line magenta

Plotting an Implicit Function

This example plots the implicitly defined function

x2 - y4 = 0

over the domain [-2π, 2π].

ezplot('x^2-y^4')
colormap([0 0 1])			% Make the line blue

See Also

ezplot3 | ezpolar | function_handle | plot

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS