Create a new path with the given vertices and codes. Parameters ---------- vertices : (N, 2) array-like The path vertices, as an array, masked array or sequence of pairs. Masked values, if any, will be converted to NaNs, which are then
(self, vertices, codes=None, _interpolation_steps=1,
closed=False, readonly=False)
| 96 | CLOSEPOLY: 1} |
| 97 | |
| 98 | def __init__(self, vertices, codes=None, _interpolation_steps=1, |
| 99 | closed=False, readonly=False): |
| 100 | """ |
| 101 | Create a new path with the given vertices and codes. |
| 102 | |
| 103 | Parameters |
| 104 | ---------- |
| 105 | vertices : (N, 2) array-like |
| 106 | The path vertices, as an array, masked array or sequence of pairs. |
| 107 | Masked values, if any, will be converted to NaNs, which are then |
| 108 | handled correctly by the Agg PathIterator and other consumers of |
| 109 | path data, such as :meth:`iter_segments`. |
| 110 | codes : array-like or None, optional |
| 111 | N-length array of integers representing the codes of the path. |
| 112 | If not None, codes must be the same length as vertices. |
| 113 | If None, *vertices* will be treated as a series of line segments. |
| 114 | _interpolation_steps : int, optional |
| 115 | Used as a hint to certain projections, such as Polar, that this |
| 116 | path should be linearly interpolated immediately before drawing. |
| 117 | This attribute is primarily an implementation detail and is not |
| 118 | intended for public use. |
| 119 | closed : bool, optional |
| 120 | If *codes* is None and closed is True, vertices will be treated as |
| 121 | line segments of a closed polygon. Note that the last vertex will |
| 122 | then be ignored (as the corresponding code will be set to |
| 123 | `CLOSEPOLY`). |
| 124 | readonly : bool, optional |
| 125 | Makes the path behave in an immutable way and sets the vertices |
| 126 | and codes as read-only arrays. |
| 127 | """ |
| 128 | vertices = _to_unmasked_float_array(vertices) |
| 129 | _api.check_shape((None, 2), vertices=vertices) |
| 130 | |
| 131 | if codes is not None and len(vertices): |
| 132 | codes = np.asarray(codes, self.code_type) |
| 133 | if codes.ndim != 1 or len(codes) != len(vertices): |
| 134 | raise ValueError("'codes' must be a 1D list or array with the " |
| 135 | "same length of 'vertices'. " |
| 136 | f"Your vertices have shape {vertices.shape} " |
| 137 | f"but your codes have shape {codes.shape}") |
| 138 | if len(codes) and codes[0] != self.MOVETO: |
| 139 | raise ValueError("The first element of 'code' must be equal " |
| 140 | f"to 'MOVETO' ({self.MOVETO}). " |
| 141 | f"Your first code is {codes[0]}") |
| 142 | elif closed and len(vertices): |
| 143 | codes = np.empty(len(vertices), dtype=self.code_type) |
| 144 | codes[0] = self.MOVETO |
| 145 | codes[1:-1] = self.LINETO |
| 146 | codes[-1] = self.CLOSEPOLY |
| 147 | |
| 148 | self._vertices = vertices |
| 149 | self._codes = codes |
| 150 | self._interpolation_steps = _interpolation_steps |
| 151 | self._update_values() |
| 152 | |
| 153 | if readonly: |
| 154 | self._vertices.flags.writeable = False |
| 155 | if self._codes is not None: |
nothing calls this directly
no test coverage detected