Specify Axis Limits - MATLAB & Simulink (2024)

Open Live Script

You can control where data appears in the axes by setting the x-axis, y-axis, and z-axis limits. You also can change where the x-axis and y-axis lines appear (2-D plots only) or reverse the direction of increasing values along each axis.

Change Axis Limits

Create a line plot. Specify the axis limits using the xlim and ylim functions. For 3-D plots, use the zlim function. Pass the functions a two-element vector of the form [min max].

x = linspace(-10,10,200); y = sin(4*x)./exp(x);plot(x,y)xlim([0 10])ylim([-0.4 0.8])

Specify Axis Limits- MATLAB & Simulink (1)

Use Semiautomatic Axis Limits

Set the maximum x-axis limit to 0 and the minimum y-axis limit to -1. Let MATLAB choose the other limits. For an automatically calculated minimum or maximum limit, use -inf or inf, respectively.

[X,Y,Z] = peaks;surf(X,Y,Z)xlabel('x-axis')ylabel('y-axis')xlim([-inf 0]) ylim([-1 inf])

Revert Back to Default Limits

Create a mesh plot and change the axis limits. Then revert back to the default limits.

[X,Y,Z] = peaks;mesh(X,Y,Z)xlim([-2 2])ylim([-2 2])zlim([-5 5])

Specify Axis Limits- MATLAB & Simulink (3)

xlim autoylim autozlim auto

Specify Axis Limits- MATLAB & Simulink (4)

Reverse Axis Direction

Control the direction of increasing values along the x-axis and y-axis by setting the XDir and YDir properties of the Axes object. Set these properties to either 'reverse' or 'normal' (the default). Use the gca command to access the Axes object.

stem(1:10)ax = gca;ax.XDir = 'reverse';ax.YDir = 'reverse';

Display Axis Lines Through Origin

By default, the x-axis and y-axis appear along the outer bounds of the axes. Change the location of the axis lines so that they cross at the origin point (0,0) by setting the XAxisLocation and YAxisLocation properties of the Axes object. Set XAxisLocation to either 'top', 'bottom', or 'origin'. Set YAxisLocation to either 'left', 'right', or 'origin'. These properties only apply to axes in a 2-D view.

x = linspace(-5,5);y = sin(x);plot(x,y)ax = gca;ax.XAxisLocation = 'origin';ax.YAxisLocation = 'origin';

Specify Axis Limits- MATLAB & Simulink (6)

Remove the axes box outline.

box off

Specify Axis Limits- MATLAB & Simulink (7)

See Also

Functions

Properties

Related Topics

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.

Specify Axis Limits- MATLAB & Simulink (8)

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:

Americas

Europe

Asia Pacific

Contact your local office

Specify Axis Limits
- MATLAB & Simulink (2024)
Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 6107

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.