Add a horizontal span (rectangle) across the Axes. The rectangle spans from *ymin* to *ymax* vertically, and, by default, the whole x-axis horizontally. The x-span can be set using *xmin* (default: 0) and *xmax* (default: 1) which are in axis units; e.g. ``
(self, ymin, ymax, xmin=0, xmax=1, **kwargs)
| 994 | |
| 995 | @_docstring.interpd |
| 996 | def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs): |
| 997 | """ |
| 998 | Add a horizontal span (rectangle) across the Axes. |
| 999 | |
| 1000 | The rectangle spans from *ymin* to *ymax* vertically, and, by default, |
| 1001 | the whole x-axis horizontally. The x-span can be set using *xmin* |
| 1002 | (default: 0) and *xmax* (default: 1) which are in axis units; e.g. |
| 1003 | ``xmin = 0.5`` always refers to the middle of the x-axis regardless of |
| 1004 | the limits set by `~.Axes.set_xlim`. |
| 1005 | |
| 1006 | Parameters |
| 1007 | ---------- |
| 1008 | ymin : float |
| 1009 | Lower y-coordinate of the span, in data units. |
| 1010 | ymax : float |
| 1011 | Upper y-coordinate of the span, in data units. |
| 1012 | xmin : float, default: 0 |
| 1013 | Lower x-coordinate of the span, in x-axis (0-1) units. |
| 1014 | xmax : float, default: 1 |
| 1015 | Upper x-coordinate of the span, in x-axis (0-1) units. |
| 1016 | |
| 1017 | Returns |
| 1018 | ------- |
| 1019 | `~matplotlib.patches.Rectangle` |
| 1020 | Horizontal span (rectangle) from (xmin, ymin) to (xmax, ymax). |
| 1021 | |
| 1022 | Other Parameters |
| 1023 | ---------------- |
| 1024 | **kwargs : `~matplotlib.patches.Rectangle` properties |
| 1025 | |
| 1026 | %(Rectangle:kwdoc)s |
| 1027 | |
| 1028 | See Also |
| 1029 | -------- |
| 1030 | axvspan : Add a vertical span across the Axes. |
| 1031 | """ |
| 1032 | # Strip units away. |
| 1033 | self._check_no_units([xmin, xmax], ['xmin', 'xmax']) |
| 1034 | (ymin, ymax), = self._process_unit_info([("y", [ymin, ymax])], kwargs) |
| 1035 | |
| 1036 | p = mpatches.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, **kwargs) |
| 1037 | p.set_transform(self.get_yaxis_transform(which="grid")) |
| 1038 | # For Rectangles and non-separable transforms, add_patch can be buggy |
| 1039 | # and update the x limits even though it shouldn't do so for an |
| 1040 | # yaxis_transformed patch, so undo that update. |
| 1041 | ix = self.dataLim.intervalx.copy() |
| 1042 | mx = self.dataLim.minposx |
| 1043 | self.add_patch(p) |
| 1044 | self.dataLim.intervalx = ix |
| 1045 | self.dataLim.minposx = mx |
| 1046 | p.get_path()._interpolation_steps = mpl.axis.GRIDLINE_INTERPOLATION_STEPS |
| 1047 | self._request_autoscale_view("y") |
| 1048 | return p |
| 1049 | |
| 1050 | @_docstring.interpd |
| 1051 | def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs): |