Skip to content

Add a "ruler" tool to the plot UI #7216

Closed

Description

@quazgar

Enhancement proposal:
Add a "ruler" like tool to the plot window.

Many other scientific data viewing programs (for example ImageJ) have this, and it is the feature I miss most often in the matplotlib plot window.

More detailed description:

  • When left-click-dragging the mouse, a line is temporarily drawn from the start to the end point.
  • Movement can be restricted to horizontal/vertical lines with the Ctrl/Shift key.
  • As the mouse is dragged, the status bar shows:
    • Total distance
    • Angle
    • Horizontal distance
    • Vertical distance

Use cases:

  • Measure the distance between peaks in a spectrum, correlation between time series, etc.
  • Manual period detection in time series.

Activity

  1. added this to the milestone on Oct 4, 2016
  2. tacaswell commented on Oct 4, 2016

    @tacaswell
    Member
  3. fariza commented on Oct 7, 2016

    @fariza
    Member

    This is a great idea and no so difficult to implement.
    For the moment I don't have the time, but if there is somebody interested I can give a hand reviewing or coaching the PR

  4. terranjp commented on Apr 16, 2017

    @terranjp

    @fariza I would be interesting in taking a stab at this PR, coaching would be helpful as I am relatively new.

    I recently developed a little tool that accomplishes most of what @quazgar described. It can be found at the distro here. I would like to develop it further with some input from others.

  5. tacaswell commented on Apr 16, 2017

    @tacaswell
    Member

    Cool! I think there are a couple possible ways to go here:

    1. a version of this code get put in widgets.py (which will require things like python 2 compatibility)
    2. we use this as the core of a 'mpl-widgets' library that lives under the matplotlib org on github and is distributed independently.
    3. you just add a blurb to the third-party library section of the docs
    4. some version of this lands in data-cursor

    All of which have pros and cons.

  6. fariza commented on Apr 17, 2017

    @fariza
    Member

    Looks awesome.
    I agree with @tacaswell widgets.py might be the best place.
    @terranjp do you have other idea?

  7. terranjp commented on Apr 18, 2017

    @terranjp

    @tacaswell @fariza Thanks for the input! It seems like widgets.py is the best fit for it. I went ahead and refactored it slightly to support python 2.7. I am looking through widgets.py now to follow the conventions used in the other widgets. I also plan to add functionality such that users can customize the ruler line and text.

    I haven't contributed to anything yet. Whats the general process?

  8. terranjp commented on Apr 18, 2017

    @terranjp

    Perfect. Thanks @tacaswell .

  9. terranjp commented on Apr 26, 2017

    @terranjp

    I am trying to figure out the best way to deal with the 'detailed text' (i.e. length, dx, dy and angle at the bottom left corner). Currently I am using a figure text and updating it as the ruler moves. This doesn't seem ideal. Is there any way to add text it to the UI like the coordinates?

    Alternatively, it would be nice to support multiple axes. Currently, the detailed texts just stack on top of each other there are multiple axes or multiple rulers in a figure. Any ideas on how to support this? I could just add more figure textgs and offset thme this gets expensive to draw, and its difficult to make sure they dont overlap.

    image

  10. fariza commented on Apr 29, 2017

    @fariza
    Member
  11. terranjp commented on Apr 29, 2017

    @terranjp

    It did not even occur to me to use a legend. Ill give it a shot. Thanks!

  12. terranjp commented on Jun 18, 2017

    @terranjp

    Finally got around to submitting a PR for this. My first contribution to an open source project and my first code to be reviewed by others. Hopefully I did it right! Feedback is appreciated!

  13. modified the milestones: , on Sep 24, 2017
  14. LindyBalboa commented on Nov 22, 2017

    @LindyBalboa
    Contributor

    Hi. First of, terranjp, thanks for taking a stab at this. This is such an essential thing that has been missing from MPL for well... ever.

    I was playing with it and I found 1 bug and 1 point for usability improvement.

    Bug: when using ctrl+m to activate/deactivate the ruler, it becomes visible upon reactivation but is no longer usable in any shape or form. It is just a static image. Also would you mind explaining why you chose ctrl+m for the binding? I don't see any mnemonic significance?

    Usability: Don't have separate modifer keys to align vertical/horizontal. Instead snap to the closest one based on the angle.

  15. terranjp commented on Nov 22, 2017

    @terranjp

    @LindyBalboa Thanks for the feedback. I just realized I let this thing fall to the wayside when I got busy with other things. Ill try and find some time to update it and submit another PR, hopefully it can be part of Matplotlib.

    I'll take a look into that bug.

    I chose 'ctrl+m' to represent 'measure'. If I remember correctly ctrl+r (for "ruler") was already bound to something. If only I had added a comment about this six months or so ago...

    I like the usability improvement. I also want to add the ability to display an angle measured from a different axis.

  16. anntzer commented on Dec 7, 2018

    @anntzer
    Contributor

    The agreement in #8774 (including from the author of the PR) was that this should go to a third-party library, so I'm going to close this.
    @terranjp If you want, you can consider making a PR adding a link to your implementation at https://matplotlib.org/thirdpartypackages/index.html.

  17. removed this from the future releases milestone on Oct 6, 2022
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions