MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _scale_polygon

Method _scale_polygon

lib/matplotlib/widgets.py:4157–4183  ·  view source on GitHub ↗

Scale the polygon selector points when the bounding box is moved or scaled. This is set as a callback on the bounding box RectangleSelector.

(self, event)

Source from the content-addressed store, hash-verified

4155
4156 @_call_with_reparented_event
4157 def _scale_polygon(self, event):
4158 """
4159 Scale the polygon selector points when the bounding box is moved or
4160 scaled.
4161
4162 This is set as a callback on the bounding box RectangleSelector.
4163 """
4164 if not self._selection_completed:
4165 return
4166
4167 if self._old_box_extents == self._box.extents:
4168 return
4169
4170 # Create transform from old box to new box
4171 x1, y1, w1, h1 = self._box._rect_bbox
4172 old_bbox = self._get_bbox()
4173 t = (transforms.Affine2D()
4174 .translate(-old_bbox.x0, -old_bbox.y0)
4175 .scale(1 / old_bbox.width, 1 / old_bbox.height)
4176 .scale(w1, h1)
4177 .translate(x1, y1))
4178
4179 # Update polygon verts. Must be a list of tuples for consistency.
4180 new_verts = [(x, y) for x, y in t.transform(np.array(self.verts))]
4181 self._xys = [*new_verts, new_verts[0]]
4182 self._draw_polygon()
4183 self._old_box_extents = self._box.extents
4184
4185 @property
4186 def _handles_artists(self):

Callers

nothing calls this directly

Calls 5

_get_bboxMethod · 0.95
_draw_polygonMethod · 0.95
translateMethod · 0.80
scaleMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected