regions icon indicating copy to clipboard operation
regions copied to clipboard

Add interactive matplotlib selector to `PolygonPixelRegion`

Open dhomeier opened this issue 4 years ago • 3 comments

As next part of the work on interactive regions #391 this PR adds an as_mpl_selector widget to the PolygonPixelRegion class to allow moving and resizing through the draw_box functionality added to PolygonSelector in matplotlib/matplotlib#21830, as well as reshaping by direct manipulation of the vertices. The draw_box handles are working analogously to the selector methods for Rectangle and Ellipse PixelRegions. Rotation is not yet included, but can be added once the mpl PR or a follow-up supports this. A centroid method is already included to provide a robust and rotation-invariant reference point. The connected PolygonSelector is ~~instantiated in a rather pedestrian manner, using several private methods, which should perhaps be replaced by a public method on the matplotlib side.~~ using the new verts.setter method for updating the vertices; tiny remaining quirk is the bounding box not being displayed after creation, but only after the first event inside.

dhomeier avatar Dec 08 '21 13:12 dhomeier

The last commit adds a method to set the rotation angle on a given Polygon instance as polygon.rotation = 30 * u.deg, and update the selector from it, if present (no test for the latter as the mpl PR is not merged) – as kind of a template for how rotation from the selector might eventually be implemented.

dhomeier avatar Dec 30 '21 15:12 dhomeier

If https://github.com/astropy/regions/pull/500 is merged first, the doc needs to be updated here too.

pllim avatar Mar 30 '23 17:03 pllim