matplotlib.pyplot.fill_between#

matplotlib.pyplot.fill_between(x,y1,y2=0,where=None,interpolate=False,step=None,*,data=None,**kwargs)[source]#

Fill the area between two horizontal curves.

The curves are defined by the points (x,y1) and (x,y2). This creates one or multiple polygons describing the filledarea.

You may exclude some horizontal sections from filling usingwhere.

By default, the edges connect the given points directly. Usestepif the filling should be a step function, i.e. constant in betweenx.

Parameters:
xarray-like

The x coordinates of the nodes defining the curves.

y1array-like or float

The y coordinates of the nodes defining the first curve.

y2array-like or float, default: 0

The y coordinates of the nodes defining the second curve.

wherearray-like of bool, optional

Definewhere to exclude some horizontal regions from being filled.The filled regions are defined by the coordinatesx[where].More precisely, fill betweenx[i] andx[i+1] ifwhere[i]andwhere[i+1]. Note that this definition impliesthat an isolatedTrue value between twoFalse values inwherewill not result in filling. Both sides of theTrue positionremain unfilled due to the adjacentFalse values.

interpolatebool, default: False

This option is only relevant ifwhere is used and the two curvesare crossing each other.

Semantically,where is often used fory1 >y2 orsimilar. By default, the nodes of the polygon defining the filledregion will only be placed at the positions in thex array.Such a polygon cannot describe the above semantics close to theintersection. The x-sections containing the intersection aresimply clipped.

Settinginterpolate toTrue will calculate the actualintersection point and extend the filled region up to this point.

step{'pre', 'post', 'mid'}, optional

Definestep if the filling should be a step function,i.e. constant in betweenx. The value determines where thestep will occur:

  • 'pre': The y value is continued constantly to the left fromeveryx position, i.e. the interval(x[i-1],x[i]]has the valuey[i].

  • 'post': The y value is continued constantly to the right fromeveryx position, i.e. the interval[x[i],x[i+1])has the valuey[i].

  • 'mid': Steps occur half-way between thex positions.

Returns:
FillBetweenPolyCollection

AFillBetweenPolyCollection containing the plotted polygons.

Other Parameters:
dataindexable object, optional

If given, the following parameters also accept a strings, which isinterpreted asdata[s] ifs is a key indata:

x,y1,y2,where

**kwargs

All other keyword arguments are passed on toFillBetweenPolyCollection. They control thePolygon properties:

Property

Description

agg_filter

a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image

alpha

array-like or float or None

animated

bool

antialiased oraa orantialiaseds

bool or list of bools

array

array-like or None

capstyle

CapStyle or {'butt', 'projecting', 'round'}

clim

(vmin: float, vmax: float)

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

cmap

Colormap or str or None

color

color or list of RGBA tuples

data

array-like

edgecolor orec oredgecolors

color or list ofcolor or 'face'

facecolor orfacecolors orfc

color or list ofcolor

figure

Figure orSubFigure

gid

str

hatch

{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}

hatch_linewidth

unknown

hatchcolor

color or list ofcolor or 'edge'

in_layout

bool

joinstyle

JoinStyle or {'miter', 'round', 'bevel'}

label

object

linestyle ordashes orlinestyles orls

str or tuple or list thereof

linewidth orlinewidths orlw

float or list of floats

mouseover

bool

norm

Normalize or str or None

offset_transform ortransOffset

Transform

offsets

(N, 2) or (2,) array-like

path_effects

list ofAbstractPathEffect

paths

list of array-like

picker

None or bool or float or callable

pickradius

float

rasterized

bool

sizes

numpy.ndarray or None

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

transform

Transform

url

str

urls

list of str or None

verts

list of array-like

verts_and_codes

unknown

visible

bool

zorder

float

See also

fill_between

Fill between two sets of y-values.

fill_betweenx

Fill between two sets of x-values.

Notes

Examples usingmatplotlib.pyplot.fill_between#

Fill the area between two lines

Fill the area between two lines