MCPcopy
hub / github.com/matplotlib/matplotlib / axvspan

Method axvspan

lib/matplotlib/axes/_axes.py:1051–1111  ·  view source on GitHub ↗

Add a vertical span (rectangle) across the Axes. The rectangle spans from *xmin* to *xmax* horizontally, and, by default, the whole y-axis vertically. The y-span can be set using *ymin* (default: 0) and *ymax* (default: 1) which are in axis units; e.g. ``ym

(self, xmin, xmax, ymin=0, ymax=1, **kwargs)

Source from the content-addressed store, hash-verified

1049
1050 @_docstring.interpd
1051 def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
1052 """
1053 Add a vertical span (rectangle) across the Axes.
1054
1055 The rectangle spans from *xmin* to *xmax* horizontally, and, by
1056 default, the whole y-axis vertically. The y-span can be set using
1057 *ymin* (default: 0) and *ymax* (default: 1) which are in axis units;
1058 e.g. ``ymin = 0.5`` always refers to the middle of the y-axis
1059 regardless of the limits set by `~.Axes.set_ylim`.
1060
1061 Parameters
1062 ----------
1063 xmin : float
1064 Lower x-coordinate of the span, in data units.
1065 xmax : float
1066 Upper x-coordinate of the span, in data units.
1067 ymin : float, default: 0
1068 Lower y-coordinate of the span, in y-axis units (0-1).
1069 ymax : float, default: 1
1070 Upper y-coordinate of the span, in y-axis units (0-1).
1071
1072 Returns
1073 -------
1074 `~matplotlib.patches.Rectangle`
1075 Vertical span (rectangle) from (xmin, ymin) to (xmax, ymax).
1076
1077 Other Parameters
1078 ----------------
1079 **kwargs : `~matplotlib.patches.Rectangle` properties
1080
1081 %(Rectangle:kwdoc)s
1082
1083 See Also
1084 --------
1085 axhspan : Add a horizontal span across the Axes.
1086
1087 Examples
1088 --------
1089 Draw a vertical, green, translucent rectangle from x = 1.25 to
1090 x = 1.55 that spans the yrange of the Axes.
1091
1092 >>> axvspan(1.25, 1.55, facecolor='g', alpha=0.5)
1093
1094 """
1095 # Strip units away.
1096 self._check_no_units([ymin, ymax], ['ymin', 'ymax'])
1097 (xmin, xmax), = self._process_unit_info([("x", [xmin, xmax])], kwargs)
1098
1099 p = mpatches.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, **kwargs)
1100 p.set_transform(self.get_xaxis_transform(which="grid"))
1101 # For Rectangles and non-separable transforms, add_patch can be buggy
1102 # and update the y limits even though it shouldn't do so for an
1103 # xaxis_transformed patch, so undo that update.
1104 iy = self.dataLim.intervaly.copy()
1105 my = self.dataLim.minposy
1106 self.add_patch(p)
1107 self.dataLim.intervaly = iy
1108 self.dataLim.minposy = my

Callers 13

__init__Method · 0.80
axvspanFunction · 0.80
test_date_axvspanFunction · 0.80
test_axvspanMethod · 0.80
test_axvspan_epochFunction · 0.80
test_twinx_knows_limitsFunction · 0.80
test_axvspanFunction · 0.80
axes_margins.pyFile · 0.80
axhspan_demo.pyFile · 0.80

Calls 8

_check_no_unitsMethod · 0.95
get_pathMethod · 0.95
_process_unit_infoMethod · 0.80
add_patchMethod · 0.80
set_transformMethod · 0.45
get_xaxis_transformMethod · 0.45
copyMethod · 0.45

Tested by 8

test_date_axvspanFunction · 0.64
test_axvspanMethod · 0.64
test_axvspan_epochFunction · 0.64
test_twinx_knows_limitsFunction · 0.64
test_axvspanFunction · 0.64