Skip to content

Pick events broken in log axes #3540

Closed

Description

@lpsinger

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]

Activity

  1. added this to the v1.4.x milestone on Sep 19, 2014
  2. WeatherGod commented on Sep 22, 2014

    @WeatherGod
    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?

  3. modified the milestones: , v1.4.x on Oct 17, 2014
  4. modified the milestones: v1.4.x, v1.4.3 on Jan 13, 2015
  5. tacaswell commented on Jan 13, 2015

    @tacaswell
    Member

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

  6. modified the milestones: v1.4.x, on Feb 7, 2015
  7. modified the milestones: , on Jul 17, 2015
  8. petehuang commented on Jan 14, 2017

    @petehuang
    Contributor

    In 1.5.3 only the left bar showed red.

    In 2.0 rc2 none showed red

  9. anntzer commented on Jan 15, 2017

    @anntzer
    Contributor

    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.

  10. anntzer commented on Jan 15, 2017

    @anntzer
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions