Skip to content

Draggable annotations: documentation and bugreport #5839

Open

Description

@Phlya

Hi, I just found out somewhere on the web that annotations can be set to be draggable by just doing:

plt.annotate(...).draggable()

This is absolutely amazing! But I don't think this is documented anywhere, while it should be (or did I miss it?).

At the same time the behaviour is not perfect: often after dragging one annotation when trying to drag another, the first one would be dragged in the same direction (e.g. I drag the second along x axis, the first one does the same). Sometimes I would get even three annotations moving when I drag one of them.

Activity

  1. tacaswell commented on Jan 12, 2016

    @tacaswell
    Member

    It is very loosely documented: http://matplotlib.org/examples/pylab_examples/annotation_demo3.html

    Odd that it is not in the API docs...

  2. Phlya commented on Jan 12, 2016

    @Phlya
    ContributorAuthor

    True, if you carefully look into that example you can realize it...

  3. tacaswell commented on Jan 12, 2016

    @tacaswell
    Member

    I agree that it should be much better documented and no one can be blamed for missing it as is.

    I only found it by git grep on the source

  4. Phlya commented on Jan 13, 2016

    @Phlya
    ContributorAuthor

    What do you think of the bug? Or is it not a bug?

  5. added this to the milestone on Jan 13, 2016
  6. tacaswell commented on Jan 13, 2016

    @tacaswell
    Member

    That is probably a bug, it would be worth having a look at the draggable selection logic. @blink1073 has been doing some very interesting / cool work with selection areas, it would be interesting to see if you could re-use any of that to make draggable annotations work better?

  7. WeatherGod commented on Jan 13, 2016

    @WeatherGod
    Member

    I am not entirely certain, but I think annotations became draggable by
    accident via the draggable legend feature. So I guess that that code never
    really got fully tested in situations with multiple annotations. Some
    example code would be useful. We can then see if it really is a bug or a
    feature.

    On Wed, Jan 13, 2016 at 8:55 AM, Thomas A Caswell notifications@github.com
    wrote:

    That is probably a bug, it would be worth having a look at the draggable
    selection logic. @blink1073 https://github.com/blink1073 has been doing
    some very interesting / cool work with selection areas, it would be
    interesting to see if you could re-use any of that to make draggable
    annotations work better?

    —
    Reply to this email directly or view it on GitHub
    #5839 (comment)
    .

  8. Phlya commented on Jan 13, 2016

    @Phlya
    ContributorAuthor

    Example code:

    import numpy as np
    import matplotlib.pyplot as plt
    x = np.arange(10)
    y = x**2
    text = [str(i) for i in zip(x, y)]
    plt.scatter(x, y)
    for a, b, c in zip(x, y, text):
        plt.annotate(c, xy=(a, b), xytext=(a, b+2), arrowprops=dict(arrowstyle="->", color='r', lw=0.5)).draggable()
    plt.show()
    

    Try dragging the annotations. Happens randomly, I think, or at least I haven't noticed a pattern.

  9. twmacro commented on May 12, 2016

    @twmacro

    I've noticed this behavior too. It does seem mostly random, but I've been able to get repeatable behavior doing this:

    • add two draggable annotations
    • move the second
    • move the first --> the second will move with it

    Oddly, if you type a command (I run in IPython with interactive on), it seems to break that link. With more annotations, I noticed that many can be linked and typing a command doesn't break all of them.

    One other thing I noticed is that the second step above causes a new ._transform member of the first annotation to be created (I only compared id's of all .__dict__ members ... before and after).

  10. modified the milestones: , on Oct 3, 2017
  11. anntzer commented on Sep 28, 2019

    @anntzer
    Contributor

    I think the bug was fixed in #10776 (somewhat indirectly); the documentation request remains.

  12. dstansby commented on Nov 16, 2019

    @dstansby
    Member

    Turns out this is the curse of private base classes again

  13. github-actions commented on Mar 21, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  14. QuLogic commented on Mar 22, 2023

    @QuLogic
    Member

    This is unfortunately still undocumented.

  15. github-actions commented on Mar 25, 2024

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  16. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationkeepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions