A path patch describing a stepwise constant function. By default, the path is not closed and starts and stops at baseline value.
| 1122 | |
| 1123 | |
| 1124 | class StepPatch(PathPatch): |
| 1125 | """ |
| 1126 | A path patch describing a stepwise constant function. |
| 1127 | |
| 1128 | By default, the path is not closed and starts and stops at |
| 1129 | baseline value. |
| 1130 | """ |
| 1131 | |
| 1132 | _edge_default = False |
| 1133 | |
| 1134 | @_docstring.interpd |
| 1135 | def __init__(self, values, edges, *, |
| 1136 | orientation='vertical', baseline=0, **kwargs): |
| 1137 | """ |
| 1138 | Parameters |
| 1139 | ---------- |
| 1140 | values : array-like |
| 1141 | The step heights. |
| 1142 | |
| 1143 | edges : array-like |
| 1144 | The edge positions, with ``len(edges) == len(vals) + 1``, |
| 1145 | between which the curve takes on vals values. |
| 1146 | |
| 1147 | orientation : {'vertical', 'horizontal'}, default: 'vertical' |
| 1148 | The direction of the steps. Vertical means that *values* are |
| 1149 | along the y-axis, and edges are along the x-axis. |
| 1150 | |
| 1151 | baseline : float, array-like or None, default: 0 |
| 1152 | The bottom value of the bounding edges or when |
| 1153 | ``fill=True``, position of lower edge. If *fill* is |
| 1154 | True or an array is passed to *baseline*, a closed |
| 1155 | path is drawn. |
| 1156 | |
| 1157 | **kwargs |
| 1158 | `Patch` properties: |
| 1159 | |
| 1160 | %(Patch:kwdoc)s |
| 1161 | """ |
| 1162 | self.orientation = orientation |
| 1163 | self._edges = np.asarray(edges) |
| 1164 | self._values = np.asarray(values) |
| 1165 | self._baseline = np.asarray(baseline) if baseline is not None else None |
| 1166 | self._update_path() |
| 1167 | super().__init__(self._path, **kwargs) |
| 1168 | |
| 1169 | def _update_path(self): |
| 1170 | if np.isnan(np.sum(self._edges)): |
| 1171 | raise ValueError('Nan values in "edges" are disallowed') |
| 1172 | if self._edges.size - 1 != self._values.size: |
| 1173 | raise ValueError('Size mismatch between "values" and "edges". ' |
| 1174 | "Expected `len(values) + 1 == len(edges)`, but " |
| 1175 | f"`len(values) = {self._values.size}` and " |
| 1176 | f"`len(edges) = {self._edges.size}`.") |
| 1177 | # Initializing with empty arrays allows supporting empty stairs. |
| 1178 | verts, codes = [np.empty((0, 2))], [np.empty(0, dtype=Path.code_type)] |
| 1179 | |
| 1180 | _nan_mask = np.isnan(self._values) |
| 1181 | if self._baseline is not None: |
no outgoing calls
no test coverage detected
searching dependent graphs…