-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add painter widget #7411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add painter widget #7411
Conversation
I think this is going to have to also listen for re-size events to update the offsets if the window is resized. |
Done. I couldn't think of a way to preserve the selection while resizing, so it gets cleared. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly minor tweaks except maybe the transform question.
examples/widgets/painter.py
Outdated
@@ -0,0 +1,30 @@ | |||
from __future__ import print_function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can go after the docstring.
@@ -0,0 +1,30 @@ | |||
from __future__ import print_function | |||
""" | |||
Drag the mouse to paint selected areas of the plot. The callback prints |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a title and such to match gallery stuff (see guidelines)?
examples/widgets/painter.py
Outdated
|
||
|
||
# Define the "on_select" callback. | ||
def test(x, y): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have a more specific name.
do_event(tool, 'onmove', xdata=110, ydata=110) | ||
do_event(tool, 'release') | ||
|
||
assert tool.overlay[tool.overlay == 2].size == 878 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do these numbers mean?
@@ -2595,3 +2598,190 @@ def onmove(self, event): | |||
self.canvas.blit(self.ax.bbox) | |||
else: | |||
self.canvas.draw_idle() | |||
|
|||
|
|||
LABELS_CMAP = ListedColormap(['white', 'red', 'dodgerblue', 'gold', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these colours? Why can't we use an existing one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where can I find an existing one?
lib/matplotlib/widgets.py
Outdated
*cursor_props* : ditc | ||
- The properties to apply to the cursor. | ||
*radius* : int | ||
- The radius of the cursor in pixels. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary bullet point. Also, indent is only 3 spaces instead of 4.
lib/matplotlib/widgets.py
Outdated
*cmap* : :class:~matplotlib.colorls.ListedColormap` | ||
- The colormap to use for the cursors. | ||
*useblit* : bool | ||
- Whether to use blitting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary bullet point. Also, indent is only 3 spaces instead of 4.
lib/matplotlib/widgets.py
Outdated
*radius* : int | ||
- The radius of the cursor in pixels. | ||
*cmap* : :class:~matplotlib.colorls.ListedColormap` | ||
- The colormap to use for the cursors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary bullet point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are the alternate colours used? I can't get the example to trigger anything other than a red square.
self._radius = r | ||
xfm = self.ax.transData.inverted() | ||
x0, y0 = xfm.transform((0, 0)) | ||
x1, y1 = xfm.transform((r, r)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally sure this will work on a polar plot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note that polar plots are not supported (to keep the implementation simpler).
self._offsety = extents[1] | ||
self._shape = (int(extents[3] - extents[1]), | ||
int(extents[2] - extents[0])) | ||
self._overlay = np.zeros(self._shape, dtype='uint8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may be able to use _image.resample
in the same way that imshow
eventually does if you want take a stab at preserving the overlay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That uses a lot of private APIs, I'd prefer to keep this simple. I added a note about the clearing behavior in the docs.
Thanks for the review, @QuLogic! I believe I had addressed all of your concerns. |
Current coverage is 62.06% (diff: 93.93%)
|
Is this something we still want for 3.0? Milestoning as such, but not because I think its a pressing need. Kinda cool though... |
Closing as too far out of date. |
If somebody is interested in this, starting as a 3rd-party-lib is a good way to accumulate user interest and stabilize the API. If both is done, we can reconsider integrating such a widget into core matplotlib later. |
Interestingly, my canvas only blacks out while licecap is running.