Set or query x-axis limits (2024)

Set or query x-axis limits

collapse all in page

Syntax

xlim(limits)

xlim(limitmethod)

xlim(limitmode)

xl = xlim

limmethod = xlim("method")

limmode = xlim("mode")

___ = xlim(target,___)

Description

Specify Limits

example

xlim(limits) sets the x-axis limits for the current axes or chart. Specify limits as a two-element vector of the form [xmin xmax], where xmax is greater than xmin.

example

xlim(limitmethod) specifies the limit method MATLAB® uses for automatic limit selection. Specify the limit method as "tickaligned", "tight", or "padded". MATLAB sets the XLimitMethod property of the axes to the value you specify. The limit method is not supported for standalone visualizations.

You can specify the limitmethod argument without parentheses. For example, xlim tight enables tight x-axis limits.

example

xlim(limitmode) specifies automatic or manual limit selection. The limitmode can have either of two values:

  • "auto" — Enable automatic limit selection. MATLAB selects the limits based on the range of your data and the value of the XLimitMethod property of the axes. If you plot into the axes multiple times, the limits update to encompass all the data.

  • "manual" — Freeze the x-axis limits at their current value.

You can specify the limitmode argument without parentheses. For example, xlim auto enables automatic limit selection.

Query Limits

example

xl = xlim returns the current limits as a two-element vector.

limmethod = xlim("method") returns the current x-axis limits method, which can be 'tickaligned', 'tight', or 'padded'.

limmode = xlim("mode") returns the current x-axis limits mode, which is either 'auto' or 'manual'. By default, the mode is automatic unless you specify limits or set the mode to manual.

Specify Target Axes or Chart

example

___ = xlim(target,___) uses the axes or standalone visualization specified by target instead of the current axes. Specify target as the first input argument for any of the previous syntaxes. You can include an output argument if the original syntax supports an output argument. Use quotes around the mode inputs, for example, xlim(target,"auto").

Examples

collapse all

Set x-Axis Limits

Open Live Script

Plot a line and set the x-axis limits to range from 0 to 5.

x = linspace(0,10);y = sin(x);plot(x,y)xlim([0 5])

Set or query x-axis limits (1)

Use Semiautomatic x-Axis Limits

Create a surface plot and show only x values greater than 0. Specify the minimum x-axis limit as 0 and let MATLAB choose the maximum limit.

[X,Y,Z] = peaks;surf(X,Y,Z)xlim([0 inf])

Set or query x-axis limits (2)

Set Limits for x-Axis with Dates

Open Live Script

Create a stem chart with dates along the x-axis. Set the x-axis limits to range from June 1, 2014 to June 5, 2014.

t = datetime(2014,06,1) + caldays(0:10);y = rand(11,1);stem(t,y,'filled')tstart = datetime(2014,06,1);tend = datetime(2014,06,5);xlim([tstart tend])

Set or query x-axis limits (3)

Specify Tight x-Axis Limits

Open Live Script

If you want the x-axis to automatically adjust to match the range of your x-coordinates, use the 'tight' limit method.

Create a line plot.

plot([1 2 3 4 5 6.3],[0 0.3 0.1 0.6 0.4 1])

Set or query x-axis limits (4)

Change the limit method to 'tight'.

xlim tight

Set or query x-axis limits (5)

Add another plot to the axes. The x-axis limits adjust to encompass the span of the new data.

hold onplot([1 2 3 4 5 8.3],[0.1 0.2 0.3 0.4 0.5 0.83])hold off

Set or query x-axis limits (6)

Set x-Axis Limits for Specific Axes

Open Live Script

Starting in R2019b, you can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Plot data into each axes. Then set the x-axis limits for the bottom plot by specifying ax2 as the first input argument to xlim.

tiledlayout(2,1)x = linspace(0,5,1000);y = sin(100*x)./exp(x);ax1 = nexttile;plot(ax1,x,y)ax2 = nexttile;plot(ax2,x,y)xlim(ax2,[0 1])

Set or query x-axis limits (7)

Maintain Current x-Axis Limits

Open Live Script

Use manual mode to maintain the current x-axis limits when you add more plots to the axes.

First, plot a line.

x = linspace(0,10);y = sin(x);plot(x,y);

Set or query x-axis limits (8)

Set the x-axis limits mode to manual so that the limits do not change. Use hold on to add a second plot to the axes.

xlim manualhold onplot(2*x,2*y)hold off

Set or query x-axis limits (9)

The x-axis limits do not update to incorporate the new plot.

Switch back to automatically updated limits by resetting the mode to automatic.

xlim auto

Set or query x-axis limits (10)

Return x-Axis Limits

Open Live Script

Create a scatter plot of random data. Return the values of the x-axis limits.

x = randn(50,1);y = randn(50,1);scatter(x,y)

Set or query x-axis limits (11)

xl = xlim
xl = 1×2 -3 4

Input Arguments

collapse all

limitsMinimum and maximum limits
two-element vector

Minimum and maximum limits, specified as a two-element vectorof the form [xmin xmax], where xmax isgreater than xmin. You can specify the limits asnumeric, categorical, datetime, or duration values. However, the typeof values that you specify must match the type of values along the x-axis.

You can specify both limits, or specify one limit and let MATLAB automatically calculate the other. For an automatically calculated minimum or maximum limit, use -inf or inf, respectively. MATLAB uses the "tight" limit method to calculate the corresponding limit.

Example: xlim([0 1])

Example: xlim([-inf 1])

Example: xlim([0 inf])

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

limitmethodLimit selection method
"tickaligned" (default) | "padded" | "tight"

Limit selection method, specified as a value from the table.

The examples in the table show the approximate appearance for each method. Your results might differ depending on your data, the size of the axes, and the type of plot you create.

ValueDescriptionExample
"tickaligned"

In general, align the edges of the axes box with the tick marks that are closest to your data without excluding any data. The appearance might vary depending on the type of data you plot and the type of chart you create.

Set or query x-axis limits (12)

"tight"

Fit the axes box tightly around the data by setting the axis limits to the data range.

Set or query x-axis limits (13)

"padded"

Fit the axes box around the data with a thin margin of padding on each side. The width of the margin is approximately 7% of the data range.

Set or query x-axis limits (14)

Note

  • The limit method has no effect when the XLimMode property of the axes is set to "manual".

  • Specifying the limit method is not supported for standalone visualizations such as heatmap or stackedplot.

limitmodeLimit mode
"auto" | "manual"

Limit mode, specified as one of the following values:

  • "auto" — Enable automatic limit selection, which is based on the total span of the data and the value of the XLimitMethod property of the axes. If you plot into the axes multiple times, the limits update to encompass all the data. You can use this option if you change the limits and want to set them back to the default values.

  • "manual" — Freeze the limits at the current values. Use this option if you want to retain the current limits when adding new data to the axes using the hold on command.

When you specify this argument, MATLAB sets the XLimMode property of the axes to the value you specify. However, the XLimMode property changes to "manual" whenever you set the x-axis limits explicitly, either by calling xlim(limits), or by setting the value of the XLim property on the axes.

targetTarget axes or chart
axes object | standalone visualization | array of axes or standalone visualizations

Target axes or chart, specified as one of the following:

  • An axes object.

  • A standalone visualization that has an XLimits property, such as a heatmap chart or a stackedplot.

  • An array of axes or standalone visualizations that belong to the same class. To determine the class, use the class function.

If you do not specify this argument, then xlim sets the limits on the graphics object returned by the gca command.

Output Arguments

collapse all

xl — Current limits
two-element vector

Current limits, returned as a two-element vector of the form [xminxmax].

Querying the limits returns the XLim or XLimits property value for corresponding Axes or graphics object.

limmethod — Current limits method
'tickaligned' | 'tight' | 'padded'

Current limits method, returned as one of these values:

  • 'tickaligned' — In general, align the edges of the axes box with the tick marks that are closest to your data without excluding any data. The appearance might vary depending on the type of data you plot and the type of chart you create.

  • 'tight' — Fit the axes box tightly around the data by setting the axis limits to the data range.

  • 'padded' — Fit the axes box around the data with a thin margin of padding on each side. The width of the margin is approximately 7% of the data range.

Querying the x-axis limits method returns the XLimitMethod property value for the corresponding Axes object.

limmode — Current limits mode
'auto' | 'manual'

Current limits mode, returned as one of these values:

  • 'auto' — Automatically determine the limits.

  • 'manual' — Use manually specified limits that do not update to reflect changes in the data.

Querying the x-axis limits mode returns the XLimMode property value for the corresponding Axes object.

Algorithms

The xlim function sets and queries severalaxes properties related to the x-axis limits.

  • XLim — Property that stores the x-axis limits.

  • XLimMode — Property that stores the x-axis limits mode. When you set the x-axis limits, this property changes to "manual".

  • XLimitMethod — Property that controls how the x-axis limits are calculated when the XLimMode property is set to "auto".

Version History

Introduced before R2006a

expand all

Query the current axis limit method using the "method" input argument.

Set the method that MATLAB uses for automatic limit selection by specifying the limitmethod argument. This argument can have a value of 'tickaligned', 'tight', or 'padded'.

See Also

Functions

  • ylim | zlim | grid | xlabel | xticks | xticklabels | xtickformat

Properties

  • Axes Properties

Topics

  • Specify Axis Limits

Commande MATLAB

Vous avez cliqué sur un lien qui correspond à cette commande MATLAB:

 

Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.

Set or query x-axis limits (15)

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

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Set or query x-axis limits (2024)

FAQs

Set or query x-axis limits? ›

xlim( limits ) sets the x-axis limits for the current axes or chart. Specify limits as a two-element vector of the form [xmin xmax] , where xmax is greater than xmin . xlim( limitmethod ) specifies the limit method MATLAB® uses for automatic limit selection.

How do you set x-axis limits in Excel? ›

Select the axis on the chart. Right-click the axis then select Format Axis in the menu. The Format Axis panel appears on the right side of the window. Under Axis Options in the Format Axis panel, set the minimum and maximum axis values by entering a value in the Minimum and Maximum boxes under Bounds.

How to set x-axis limits in R? ›

A: To set XLim and YLim in base R, use the xlim and ylim arguments in your plotting function. For example, plot(x, y, xlim=c(1, 10), ylim=c(0, 20)) sets the x-axis to range from 1 to 10 and the y-axis from 0 to 20.

How to set x-axis limits in Python? ›

The xlim() function in pyplot module of matplotlib library is used to get or set the x-limits of the current axes. Parameters: This method accept the following parameters that are described below: left: This parameter is used to set the xlim to left. right: This parameter is used to set the xlim to right.

Which function would you use to set the limits for x-axis of the plot? ›

Get or set the x limits of the current Axes. Setting limits turns autoscaling off for the x-axis.

How to change X-axis data range in Excel? ›

Choose Insert > Chart > Line. With the chart selected, in the Chart Design ribbon click Select Data. In the Select Data Source dialog, click in the Horizontal (Category) axis labels edit box, and select the X text (or numerical) values on the worksheet. Click OK.

How to customize X-axis values in Excel? ›

Right-click on the X-axis and then click on Format Axis. 3. Now click on Axis Options button and in the Labels option, under Interval between labels, select Specify interval unit and type your desired interval value in the box next to it.

How to limit X axis on Ggplot? ›

How to Set Axis Limits in ggplot2?, ggplot2 can frequently be used to set the axis bounds on a plot. The following functions make it simple to accomplish this: xlim(): defines the x-axis's lowest and upper limits. ylim(): defines the y-axis's lower and upper limits.

How to scale x axis in R? ›

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

How to change x-axis intervals in R? ›

1 Answer. This is where you need to use xlim() and ylim() methods. For xlim() you need to pass two numeric values, specifying the left and the right values of your desired interval. For ylim() you need to pass two numeric values, specifying the lower and the upper values of your desired interval.

How to limit x and y-axis in Python? ›

Setting Axis Limits Using set_xlim() and set_ylim()

These methods allow you to define the range of values displayed on the x-axis and y-axis, respectively. In this example, set_xlim(0, 5) ensures that the x-axis starts at 0 and ends at 5, while set_ylim(0, 20) sets the y-axis range from 0 to 20.

What is the difference between Set_xlim and Set_xbound? ›

set_xlim − Set the X-axis view limits. set_xbound − Set the lower and upper numerical bounds of the X-axis. Using subplots(2), we can create a figure and a set of subplots.

What is the difference between Xticks and Xlim? ›

They are different. The first ( plt. xlim() ) returns range for x-axis values of the current axes-instance, the second returns array of xtick labels (where labels will be placed) within the interval returned by xlim .

How do you set the x-axis on a plot? ›

To set the x-axis values, we use the xticks function. This function takes two arguments: the locations along the x-axis where the ticks will be placed, and the labels for these ticks. In this example, np. arange(0, 11, step=1) generates an array of numbers from 0 to 10 (inclusive) with a step of 1.

How to set the y-axis range in Python? ›

The simplest way to set the axis range in Matplotlib is by using the xlim() and ylim() functions. These functions allow you to define the minimum and maximum values that will be displayed on the X and Y axes, respectively. In the above example, we've set the X-axis to range from 0 to 5 and the Y-axis from 0 to 20.

What is the over x-axis rule? ›

To reflect over the x-axis, change the sign on the y coordinates of selected given points. Reflections over the y-axis require the x coordinated to be negated. Reflections over the origin require that both the x and y coordinates be negated, and to reflect over the line y=x, swap x and y.

How do I change the X-axis gap in Excel? ›

On the Format tab, in the Current Selection group, click Format Selection. Under Axis Options, do one or both of the following: To change the interval between axis labels, under Interval between labels, click Specify interval unit, and then in the text box, type the number that you want.

How do I set a maximum value limit in Excel? ›

From the Allow list, select Whole number. In the Data box, select the type of restriction that you want. For example, to set upper and lower limits, select between. Enter the minimum, maximum, or specific value to allow.

How do I change the axis maximum and minimum in Excel? ›

Changing the scale of the axis: You can customize and modify the overall scale, interval and range of each axis in Excel using the "Format Axis" menu. Open the menu by right-clicking on an axis, then input the minimum and maximum values for the axis in the dialog box.

How do I set character limits in Excel? ›

Limiting the number of characters in Excel is easy. First, select the cells you wish to limit. Then, go to the “Data” tab and select “Data Validation.” In the data validation window, select “Text Length” from the drop-down menu and enter the desired maximum number of characters. Click “o*k” and you're done.

Top Articles
10 of the Best W. B. Yeats Poems
William Butler Yeats | Poetry Foundation
Menards Thermal Fuse
Using GPT for translation: How to get the best outcomes
What Are Romance Scams and How to Avoid Them
Dew Acuity
What Happened To Dr Ray On Dr Pol
T&G Pallet Liquidation
Aita Autism
Https //Advanceautoparts.4Myrebate.com
Love In The Air Ep 9 Eng Sub Dailymotion
Patrick Bateman Notebook
Arre St Wv Srj
Marvon McCray Update: Did He Pass Away Or Is He Still Alive?
Royal Cuts Kentlands
Rufus Benton "Bent" Moulds Jr. Obituary 2024 - Webb & Stephens Funeral Homes
All Obituaries | Gateway-Forest Lawn Funeral Home | Lake City FL funeral home and cremation Lake City FL funeral home and cremation
Airtable Concatenate
1 Filmy4Wap In
Watson 853 White Oval
Play It Again Sports Forsyth Photos
Helloid Worthington Login
Devotion Showtimes Near The Grand 16 - Pier Park
Craigs List Tallahassee
Ravens 24X7 Forum
Baddies Only .Tv
Desirulez.tv
Supermarkt Amsterdam - Openingstijden, Folder met alle Aanbiedingen
Appraisalport Com Dashboard /# Orders
Craigslist Red Wing Mn
Pensacola 311 Citizen Support | City of Pensacola, Florida Official Website
Go Smiles Herndon Reviews
Planet Fitness Santa Clarita Photos
Jail View Sumter
Adam Bartley Net Worth
Prior Authorization Requirements for Health Insurance Marketplace
Pro-Ject’s T2 Super Phono Turntable Is a Super Performer, and It’s a Super Bargain Too
Pokemon Reborn Gyms
Sand Castle Parents Guide
About Us
Spurs Basketball Reference
Amy Zais Obituary
Air Sculpt Houston
How the Color Pink Influences Mood and Emotions: A Psychological Perspective
Gonzalo Lira Net Worth
Mega Millions Lottery - Winning Numbers & Results
Wzzm Weather Forecast
Bedbathandbeyond Flemington Nj
Guy Ritchie's The Covenant Showtimes Near Look Cinemas Redlands
28 Mm Zwart Spaanplaat Gemelamineerd (U999 ST9 Matte | RAL9005) Op Maat | Zagen Op Mm + ABS Kantenband
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 6102

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.