You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Handling pick events does not work on logarithmic axes. See the example below. As long as the line statement ax.set_xscale('log') is commented out, clicking on the polygons created by axvspan xauses them to change from gray to red. Uncomment that line to make the x axis logarithmic, and clicking on the polygons has either no effect or is misdirected to the far-left polygon only.
frommatplotlibimportpyplotaspltfig=plt.figure()
ax=fig.add_subplot(111)
ax.set_xlim(1, 10)
foriinrange(1, 10, 3):
ax.axvspan(i, i+1, color='gray', picker=True)
# uncomment this line to break the picker# ax.set_xscale('log')defonpick(event):
event.artist.set_color('red')
fig.canvas.draw()
fig.canvas.mpl_connect('pick_event', onpick)
plt.show()
Tested on version 1.4.0 and master as of 04496b0 on Mac OS X Mavericks.
Additional note, this seems to be limited to just the axvspan (and I suspect the axhspan). If I modify the above code to do a plot instead of axvspan, the objects respond to pick events. I suspect it might be something wrong with the transform handling. Maybe the picker code is not using the artist's transforms object?
This is apparently due to _point_in_path not handling nonlinear transforms, and affects basically any path-containment-check in nonlinear axes. The following patch fixes the issue:
diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py
index 58e984d2c..e4c567898 100644
--- a/lib/matplotlib/path.py
+++ b/lib/matplotlib/path.py
@@ -492,10 +492,8 @@ class Path(object):
smaller.
"""
if transform is not None:
- transform = transform.frozen()
- result = _path.point_in_path(point[0], point[1], radius, self,
- transform)
- return result
+ self = transform.transform_path(self)
+ return _path.point_in_path(point[0], point[1], radius, self, None)
def contains_points(self, points, transform=None, radius=0.0):
"""
but it probably needs a test, and I guess there is some memory cost to maintaining the entire transformed path in memory (but I guess that transformed path will have to be computed at draw time anyways so perhaps it should (is already?) be cached somewhere.
I was wondering whether you could inverse-transform the point, rather than forward-transform the path (and then there's no memory cost anymore), but for really weird nonseparable transforms it may be not the same? (You can imagine a line that originally passes above a point curve below it after application of the transform... perhaps.)
Edit: clearly that won't work -- imagine the case, in a polar plot, of three points at r=1 and thetas=0, 120, 240 forming a triangle; if we don't transform the path first it will appear as empty.
Activity
WeatherGod commentedon Sep 22, 2014
Additional note, this seems to be limited to just the axvspan (and I suspect the axhspan). If I modify the above code to do a plot instead of axvspan, the objects respond to pick events. I suspect it might be something wrong with the transform handling. Maybe the picker code is not using the artist's transforms object?
tacaswell commentedon Jan 13, 2015
Punting on this again, I don't think this is a blocker as it is reportedly limited to the span objects.
petehuang commentedon Jan 14, 2017
In 1.5.3 only the left bar showed red.
In 2.0 rc2 none showed red
anntzer commentedon Jan 15, 2017
This is apparently due to
_point_in_pathnot handling nonlinear transforms, and affects basically any path-containment-check in nonlinear axes. The following patch fixes the issue:but it probably needs a test, and I guess there is some memory cost to maintaining the entire transformed path in memory (but I guess that transformed path will have to be computed at draw time anyways so perhaps it should (is already?) be cached somewhere.
anntzer commentedon Jan 15, 2017
I was wondering whether you could inverse-transform the point, rather than forward-transform the path (and then there's no memory cost anymore), but for really weird nonseparable transforms it may be not the same? (You can imagine a line that originally passes above a point curve below it after application of the transform... perhaps.)
Edit: clearly that won't work -- imagine the case, in a polar plot, of three points at r=1 and thetas=0, 120, 240 forming a triangle; if we don't transform the path first it will appear as empty.