matplotlib icon indicating copy to clipboard operation
matplotlib copied to clipboard

Fix PolygonSelector.clear()

Open lschr opened this issue 2 years ago • 2 comments

PR Summary

This PR implements PolygonSelector.clear() to delete all vertices and enable visibility.

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • [x] Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

lschr avatar Sep 14 '22 10:09 lschr

Thank you for your work on this and I think overall it makes sense however I have a couple questions.

This looks like this will call self.update twice, once through _draw_polygon and once through super().clear() Is there a way to get this down to just one call to update (we have a lot of performance issuses that boil down to "we do the same thing N times when once would do")?

Why enable visibilty what the base-class turns it off?

Can you add a test?

tacaswell avatar Sep 15 '22 16:09 tacaswell

Why enable visibilty what the base-class turns it off?

Otherwise the selection widget is not visible after calling clear. Visibility is also enabled explicitly in __init__. I guess PolygonSelector is implemented a little differently.

This looks like this will call self.update twice, once through _draw_polygon and once through super().clear() Is there a way to get this down to just one call to update (we have a lot of performance issuses that boil down to "we do the same thing N times when once would do")?

I guess, it would be smarter to call self._clear_without_update() instead of super().clear(). However, since this is just

def _clear_without_update(self):
    self._selection_completed = False
    self.set_visible(False)

it would also be possible to skip the call and re-enabling visibility altogether, and PolygonSelector.clear would become

def clear(self):
    self._selection_completed = False
    self._xys = [(0, 0)]
    self._draw_polygon()

What would you suggest?

lschr avatar Sep 20 '22 01:09 lschr

Otherwise the selection widget is not visible after calling clear. Visibility is also enabled explicitly in init. I guess PolygonSelector is implemented a little differently.

fair. Looking at this more carefully I see what you mean about PolygonSelector having slightly different notions of what the "right" visibility / transient state is....

The best path here may be to override _clear_without_update() ?


Sorry this fell off my radar, are you still interested in working on this @lschr ?

tacaswell avatar Dec 16 '22 19:12 tacaswell

Feel free to mark ready for review when it's ready! Thanks

jklymak avatar Jan 26 '23 02:01 jklymak

I just rebased on current main, updated the code to call update() only once and added a test.

@tacaswell can you have another look? I don't think the failing tests are related to this.

lschr avatar May 05 '23 13:05 lschr

Thanks @lschr! Congratulations on your first PR to Matplotlib :tada: We hope to hear from you again.

QuLogic avatar May 11 '23 08:05 QuLogic