Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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
quazgar opened this issue Oct 4, 2016 · 15 comments
Closed

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

quazgar opened this issue Oct 4, 2016 · 15 comments

Comments

@quazgar
Copy link

quazgar commented Oct 4, 2016

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.
@tacaswell tacaswell added this to the 2.1 (next point release) milestone Oct 4, 2016
@tacaswell
Copy link
Member

attn @OceanWolf @fariza

@fariza
Copy link
Member

fariza commented Oct 7, 2016

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

@terranjp
Copy link

terranjp commented Apr 16, 2017

@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.

@tacaswell
Copy link
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.

@fariza
Copy link
Member

fariza commented Apr 17, 2017

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

@terranjp
Copy link

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

@tacaswell
Copy link
Member

@terranjp
Copy link

Perfect. Thanks @tacaswell .

@terranjp
Copy link

terranjp commented Apr 26, 2017

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

@fariza
Copy link
Member

fariza commented Apr 29, 2017 via email

@terranjp
Copy link

terranjp commented Apr 29, 2017

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

@terranjp
Copy link

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!

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Sep 24, 2017
@LindyBalboa
Copy link
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.

@terranjp
Copy link

@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.

@anntzer
Copy link
Contributor

anntzer commented Dec 7, 2018

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.

@anntzer anntzer closed this as completed Dec 7, 2018
@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants