matplotlib.axes.Axes.set_xlim#

Axes.set_xlim(left=None, right=None, *, emit=True, auto=False, xmin=None, xmax=None)[source]#

Set the x-axis view limits.

Parameters:
leftfloat, optional

The left xlim in data coordinates. Passing None leaves the limit unchanged.

The left and right xlims may also be passed as the tuple (left, right) as the first positional argument (or as the left keyword argument).

rightfloat, optional

The right xlim in data coordinates. Passing None leaves the limit unchanged.

emitbool, default: True

Whether to notify observers of limit change.

autobool or None, default: False

Whether to turn on autoscaling of the x-axis. True turns on, False turns off, None leaves unchanged.

xmin, xmaxfloat, optional

They are equivalent to left and right respectively, and it is an error to pass both xmin and left or xmax and right.

Returns:
left, right(float, float)

The new x-axis limits in data coordinates.

Notes

The left value may be greater than the right value, in which case the x-axis values will decrease from left to right.

Examples

>>> set_xlim(left, right)
>>> set_xlim((left, right))
>>> left, right = set_xlim(left, right)

One limit may be left unchanged.

>>> set_xlim(right=right_lim)

Limits may be passed in reverse order to flip the direction of the x-axis. For example, suppose x represents the number of years before present. The x-axis limits might be set like the following so 5000 years ago is on the left of the plot and the present is on the right.

>>> set_xlim(5000, 0)

Examples using matplotlib.axes.Axes.set_xlim#

Bar Label Demo

Bar Label Demo

Bar Label Demo
Broken Barh

Broken Barh

Broken Barh
CSD Demo

CSD Demo

CSD Demo
EventCollection Demo

EventCollection Demo

EventCollection Demo
Markevery Demo

Markevery Demo

Markevery Demo
Contouring the solution space of optimizations

Contouring the solution space of optimizations

Contouring the solution space of optimizations
Image Nonuniform

Image Nonuniform

Image Nonuniform
pcolormesh grids and shading

pcolormesh grids and shading

pcolormesh grids and shading
Axes box aspect

Axes box aspect

Axes box aspect
Axes Demo

Axes Demo

Axes Demo
Figure labels: suptitle, supxlabel, supylabel

Figure labels: suptitle, supxlabel, supylabel

Figure labels: suptitle, supxlabel, supylabel
Invert Axes

Invert Axes

Invert Axes
Zoom region inset axes

Zoom region inset axes

Zoom region inset axes
Boxplots

Boxplots

Boxplots
Violin plot customization

Violin plot customization

Violin plot customization
Including upper and lower limits in error bars

Including upper and lower limits in error bars

Including upper and lower limits in error bars
Bar of pie

Bar of pie

Bar of pie
AnnotationBbox demo

AnnotationBbox demo

AnnotationBbox demo
Using a text as a Path

Using a text as a Path

Using a text as a Path
Text Rotation Relative To Line

Text Rotation Relative To Line

Text Rotation Relative To Line
Annotate Transform

Annotate Transform

Annotate Transform
Mmh Donuts!!!

Mmh Donuts!!!

Mmh Donuts!!!
Ellipse Demo

Ellipse Demo

Ellipse Demo
Line Collection

Line Collection

Line Collection
Inset Locator Demo2

Inset Locator Demo2

Inset Locator Demo2
Parasite Simple2

Parasite Simple2

Parasite Simple2
axis_direction demo

axis_direction demo

axis_direction demo
Parasite Axes demo

Parasite Axes demo

Parasite Axes demo
Parasite axis demo

Parasite axis demo

Parasite axis demo
Simple Axis Pad

Simple Axis Pad

Simple Axis Pad
Anatomy of a figure

Anatomy of a figure

Anatomy of a figure
Stock prices over 32 years

Stock prices over 32 years

Stock prices over 32 years
XKCD

XKCD

XKCD
Decay

Decay

Decay
Rain simulation

Rain simulation

Rain simulation
Path Editor

Path Editor

Path Editor
Poly Editor

Poly Editor

Poly Editor
Resampling Data

Resampling Data

Resampling Data
Zoom Window

Zoom Window

Zoom Window
Custom projection

Custom projection

Custom projection
Building histograms using Rectangles and PolyCollections

Building histograms using Rectangles and PolyCollections

Building histograms using Rectangles and PolyCollections
SVG Filter Line

SVG Filter Line

SVG Filter Line
TickedStroke patheffect

TickedStroke patheffect

TickedStroke patheffect
Plot 2D data on 3D plot

Plot 2D data on 3D plot

Plot 2D data on 3D plot
Draw flat objects in 3D plot

Draw flat objects in 3D plot

Draw flat objects in 3D plot
Text annotations in 3D

Text annotations in 3D

Text annotations in 3D
Asinh Demo

Asinh Demo

Asinh Demo
Loglog Aspect

Loglog Aspect

Loglog Aspect
Scales

Scales

Scales
MRI with EEG

MRI with EEG

MRI with EEG
SkewT-logP diagram: using transforms and custom projections

SkewT-logP diagram: using transforms and custom projections

SkewT-logP diagram: using transforms and custom projections
Multiple Yaxis With Spines

Multiple Yaxis With Spines

Multiple Yaxis With Spines
Custom spine bounds

Custom spine bounds

Custom spine bounds
Formatting date ticks using ConciseDateFormatter

Formatting date ticks using ConciseDateFormatter

Formatting date ticks using ConciseDateFormatter
Date Demo Convert

Date Demo Convert

Date Demo Convert
Annotation with units

Annotation with units

Annotation with units
Artist tests

Artist tests

Artist tests
Annotate Text Arrow

Annotate Text Arrow

Annotate Text Arrow
Connect Simple01

Connect Simple01

Connect Simple01
Annotated Cursor

Annotated Cursor

Annotated Cursor
Cursor

Cursor

Cursor
Span Selector

Span Selector

Span Selector
Path Tutorial

Path Tutorial

Path Tutorial
Transformations Tutorial

Transformations Tutorial

Transformations Tutorial
Specifying Colors

Specifying Colors

Specifying Colors
Choosing Colormaps in Matplotlib

Choosing Colormaps in Matplotlib

Choosing Colormaps in Matplotlib