Test whether the mouse event occurred in the patch. Parameters ---------- mouseevent : `~matplotlib.backend_bases.MouseEvent` Where the user clicked. radius : float, optional Additional margin on the patch in target coordinates of
(self, mouseevent, radius=None)
| 129 | return _radius |
| 130 | |
| 131 | def contains(self, mouseevent, radius=None): |
| 132 | """ |
| 133 | Test whether the mouse event occurred in the patch. |
| 134 | |
| 135 | Parameters |
| 136 | ---------- |
| 137 | mouseevent : `~matplotlib.backend_bases.MouseEvent` |
| 138 | Where the user clicked. |
| 139 | |
| 140 | radius : float, optional |
| 141 | Additional margin on the patch in target coordinates of |
| 142 | `.Patch.get_transform`. See `.Path.contains_point` for further |
| 143 | details. |
| 144 | |
| 145 | If `None`, the default value depends on the state of the object: |
| 146 | |
| 147 | - If `.Artist.get_picker` is a number, the default |
| 148 | is that value. This is so that picking works as expected. |
| 149 | - Otherwise if the edge color has a non-zero alpha, the default |
| 150 | is half of the linewidth. This is so that all the colored |
| 151 | pixels are "in" the patch. |
| 152 | - Finally, if the edge has 0 alpha, the default is 0. This is |
| 153 | so that patches without a stroked edge do not have points |
| 154 | outside of the filled region report as "in" due to an |
| 155 | invisible edge. |
| 156 | |
| 157 | |
| 158 | Returns |
| 159 | ------- |
| 160 | (bool, empty dict) |
| 161 | """ |
| 162 | if self._different_canvas(mouseevent): |
| 163 | return False, {} |
| 164 | radius = self._process_radius(radius) |
| 165 | codes = self.get_path().codes |
| 166 | if codes is not None: |
| 167 | vertices = self.get_path().vertices |
| 168 | # if the current path is concatenated by multiple sub paths. |
| 169 | # get the indexes of the starting code(MOVETO) of all sub paths |
| 170 | idxs, = np.where(codes == Path.MOVETO) |
| 171 | # Don't split before the first MOVETO. |
| 172 | idxs = idxs[1:] |
| 173 | subpaths = map( |
| 174 | Path, np.split(vertices, idxs), np.split(codes, idxs)) |
| 175 | else: |
| 176 | subpaths = [self.get_path()] |
| 177 | inside = any( |
| 178 | subpath.contains_point( |
| 179 | (mouseevent.x, mouseevent.y), self.get_transform(), radius) |
| 180 | for subpath in subpaths) |
| 181 | return inside, {} |
| 182 | |
| 183 | def contains_point(self, point, radius=None): |
| 184 | """ |
no test coverage detected