matplotlib.axes.Axes.set_ylim#

Axes.set_ylim(bottom=None, top=None, *, emit=True, auto=False, ymin=None, ymax=None)[source]#

Set the y-axis view limits.

Parameters:
bottomfloat, optional

The bottom ylim in data coordinates. Passing None leaves the limit unchanged.

The bottom and top ylims may also be passed as the tuple (bottom, top) as the first positional argument (or as the bottom keyword argument).

topfloat, optional

The top ylim 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 y-axis. True turns on, False turns off, None leaves unchanged.

ymin, ymaxfloat, optional

They are equivalent to bottom and top respectively, and it is an error to pass both ymin and bottom or ymax and top.

Returns:
bottom, top(float, float)

The new y-axis limits in data coordinates.

Notes

The bottom value may be greater than the top value, in which case the y-axis values will decrease from bottom to top.

Examples

>>> set_ylim(bottom, top)
>>> set_ylim((bottom, top))
>>> bottom, top = set_ylim(bottom, top)

One limit may be left unchanged.

>>> set_ylim(top=top_lim)

Limits may be passed in reverse order to flip the direction of the y-axis. For example, suppose y represents depth of the ocean in m. The y-axis limits might be set like the following so 5000 m depth is at the bottom of the plot and the surface, 0 m, is at the top.

>>> set_ylim(5000, 0)

Examples using matplotlib.axes.Axes.set_ylim#

Grouped bar chart with labels

Grouped bar chart with labels

Grouped bar chart with labels
Broken Barh

Broken Barh

Broken Barh
EventCollection Demo

EventCollection Demo

EventCollection Demo
Hat graph

Hat graph

Hat graph
Markevery Demo

Markevery Demo

Markevery Demo
Psd Demo

Psd Demo

Psd 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 Demo

Axes Demo

Axes Demo
Broken Axis

Broken Axis

Broken Axis
Figure labels: suptitle, supxlabel, supylabel

Figure labels: suptitle, supxlabel, supylabel

Figure labels: suptitle, supxlabel, supylabel
Zoom region inset axes

Zoom region inset axes

Zoom region inset axes
Boxplots

Boxplots

Boxplots
Annotate Transform

Annotate Transform

Annotate Transform
Annotating a plot

Annotating a plot

Annotating a plot
AnnotationBbox demo

AnnotationBbox demo

AnnotationBbox demo
Using a text as a Path

Using a text as a Path

Using a text as a Path
Line, Poly and RegularPoly Collection with autoscaling

Line, Poly and RegularPoly Collection with autoscaling

Line, Poly and RegularPoly Collection with autoscaling
Mmh Donuts!!!

Mmh Donuts!!!

Mmh Donuts!!!
Ellipse Demo

Ellipse Demo

Ellipse Demo
Plotting multiple lines with a LineCollection

Plotting multiple lines with a LineCollection

Plotting multiple lines with a LineCollection
Inset locator demo 2

Inset locator demo 2

Inset locator demo 2
Parasite Simple2

Parasite Simple2

Parasite Simple2
axis_direction demo

axis_direction demo

axis_direction demo
Simple Axis Pad

Simple Axis Pad

Simple Axis Pad
Simple Axisline

Simple Axisline

Simple Axisline
Anatomy of a figure

Anatomy of a figure

Anatomy of a figure
Integral as the area under a curve

Integral as the area under a curve

Integral as the area under a curve
XKCD

XKCD

XKCD
Decay

Decay

Decay
Animated histogram

Animated histogram

Animated histogram
Rain simulation

Rain simulation

Rain simulation
MATPLOTLIB **UNCHAINED**

MATPLOTLIB UNCHAINED

MATPLOTLIB **UNCHAINED**
Data browser

Data browser

Data browser
Path editor

Path editor

Path editor
Pick event demo 2

Pick event demo 2

Pick event demo 2
Poly Editor

Poly Editor

Poly Editor
Zoom Window

Zoom Window

Zoom Window
Custom projection

Custom projection

Custom projection
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
Log Demo

Log Demo

Log Demo
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
Annotation with units

Annotation with units

Annotation with units
Artist tests

Artist tests

Artist tests
Annotated cursor

Annotated cursor

Annotated cursor
Cursor

Cursor

Cursor
Span Selector

Span Selector

Span Selector
Annotate Text Arrow

Annotate Text Arrow

Annotate Text Arrow
Connect Simple01

Connect Simple01

Connect Simple01
Quick start guide

Quick start guide

Quick start guide
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
Annotations

Annotations

Annotations