A busy icon appears every time the mouse goes off the axes and the cursor is cleared.
For image files ~100MB, the busy icon lasts 1-2 seconds each time.
Sample code:
frommatplotlib.widgetsimportCursorfrommatplotlibimportpyplotaspltfrommatplotlibimportcmfromPILimportImagefig, ax=plt.subplots()
img=Image.open(r"Path to large image file ~100MB")
ax.imshow(img, cmap=cm.gray)
cursor=Cursor(ax, useblit=True, color='red', linewidth=1)
plt.show()
Proposed solution
I think the behavior of not clearing the cursor when the mouse goes off the axes is acceptable.
It is also consistent with the behavior of the similar class MultiCursor which doesn't call canvas.draw.
If accepted, the following lines can be removed and needclear will also be removed:
I sort of agree that in general it may not be a problem if the cursor is not cleared. However, I was thinking that one possibly can add a keyword argument that can be used to control this so that we do not break any previous behavior, but allowing users to avoid clearing it if it is beneficial/acceptable.
Maybe clearoutside (or a better name), which defaults to True and then something like
if self._clearoutside and self.needclear:
self.canvas.draw()
self.needclear = False
or maybe even an early return before setting it to non-visible?
(Edit: probably one would like to consider enabling clearing for MultiCursors...)
(Edit 2: as needclear is, sort of, public, we would also need to go through the deprecation dance. Hence, probably easier to optionally disable it.)
It seems clear that needclear should have been private, and should be made so via deprecation.
I didn't really look in depth but why does Cursor even need to clear and redraw everything when the mouse goes off the axis?
I didn't really look in depth but why does Cursor even need to clear and redraw everything when the mouse goes off the axis?
It is quite nice once you have it. However not clear why it has to redraw everything and cannot rely on the normal drawing/blitting. Probably an easy, but not efficient, way to do it.
Activity
jklymak commented on Sep 27, 2023
@anntzer @oscargus either of you have any comments about this?
oscargus commented on Sep 27, 2023
I sort of agree that in general it may not be a problem if the cursor is not cleared. However, I was thinking that one possibly can add a keyword argument that can be used to control this so that we do not break any previous behavior, but allowing users to avoid clearing it if it is beneficial/acceptable.
Maybe clearoutside (or a better name), which defaults to True and then something like
if self._clearoutside and self.needclear: self.canvas.draw() self.needclear = Falseor maybe even an early return before setting it to non-visible?
(Edit: probably one would like to consider enabling clearing for MultiCursors...)
(Edit 2: as needclear is, sort of, public, we would also need to go through the deprecation dance. Hence, probably easier to optionally disable it.)
anntzer commented on Sep 28, 2023
It seems clear that needclear should have been private, and should be made so via deprecation.
I didn't really look in depth but why does Cursor even need to clear and redraw everything when the mouse goes off the axis?
oscargus commented on Sep 28, 2023
It is quite nice once you have it. However not clear why it has to redraw everything and cannot rely on the normal drawing/blitting. Probably an easy, but not efficient, way to do it.
komoto48g commented on Sep 29, 2023
Thank you for your review.
I added the following monkey patch to my program and it worked fine for me.
Since events.xdata and ydata return None , it is simply cleared rather than drawn.
(In the latest version, _get_data_coords would be better)
Fix: Prevent Cursor from forcing full canvas draw when useblit=True (m…