Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Change Axis Limits of Graph

This example shows how to change the axis limits of a graph. By default, MATLAB® chooses axis limits to encompass the data plotted.

Create Simple Line Plot

Define x as 200 linearly spaced values between -10 and 10. Define y as the sine of x with an exponentially decreasing amplitude. Create a line plot of the data.

x = linspace(-10,10,200);
y = sin(4*x)./exp(x);

figure
plot(x,y)

Change Axis Limits

Change the axis limits by passing to the axis function a four-element vector of the form [xmin,xmax,ymin,ymax], where xmin and xmax set the scaling for the x-axis, and ymin and ymax set the scaling for the y-axis.

You also can change the axis limits using the xlim, ylim, and zlim functions. The commands xlim([xmin,xmax]) and ylim([ymin,ymax]) produce the same result as axis([xmin,xmax,ymin,ymax]).

Change the x-axis scaling to range from 0 to 10. Change the y-axis scaling to range from -1 to 1.

axis([0,10,-1,1])

Use Semiautomatic Axis Limits

Use an automatically calculated minimum x-axis limit by settings its value to -inf. MATLAB® calculates the limit based on the data. Specify values for the maximum x-axis limit and the y-axis limits.

axis([-inf,10,-1,1])

To use an automatically calculated maximum limit, set the value to inf.

See Also

| | | |

Related Examples

Was this topic helpful?