Skip to content

Pick events broken in log axes #3540

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

Closed
lpsinger opened this issue Sep 19, 2014 · 5 comments · Fixed by #7844
Closed

Pick events broken in log axes #3540

lpsinger opened this issue Sep 19, 2014 · 5 comments · Fixed by #7844

Comments

@lpsinger
Copy link
Contributor

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.

    from matplotlib import pyplot as plt
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.set_xlim(1, 10)
    for i in range(1, 10, 3):
        ax.axvspan(i, i + 1, color='gray', picker=True)

    # uncomment this line to break the picker
    # ax.set_xscale('log')

    def onpick(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.

[TAC edited for formatting]

@tacaswell tacaswell added this to the v1.4.x milestone Sep 19, 2014
@WeatherGod
Copy link
Member

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
Copy link
Member

Punting on this again, I don't think this is a blocker as it is reportedly limited to the span objects.

@tacaswell tacaswell modified the milestones: v1.4.x, 1.5.0 Feb 7, 2015
@tacaswell tacaswell modified the milestones: proposed next point release, next point release Jul 17, 2015
@petehuang
Copy link
Contributor

In 1.5.3 only the left bar showed red.

In 2.0 rc2 none showed red

@anntzer
Copy link
Contributor

anntzer commented Jan 15, 2017

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.

@anntzer
Copy link
Contributor

anntzer commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants