Skip to content
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

set_position on Annotation is not working #2329

Closed
alefnula opened this issue Aug 22, 2013 · 3 comments
Closed

set_position on Annotation is not working #2329

alefnula opened this issue Aug 22, 2013 · 3 comments

Comments

@alefnula
Copy link
Contributor

annotation.set_position(...) is not working in versions 1.2.1, 1.3.0 nor on the master.

Here is an example that demonstrates this.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

# Create initial data
data = np.array([[1,2,3,4,5], [7,4,9,2,3]])

# Create figure and axes
fig = plt.figure()
ax = plt.axes(xlim=(0, 20), ylim=(0, 20))

# Create initial objects
line, = ax.plot([], [], 'r-')
annotation = ax.annotate('A0', xy=(data[0][0], data[1][0]))
annotation.set_animated(True)

def init():
    return line, annotation

def update(num):
    newData = np.array([[1 + num, 2 + num / 2, 3, 4 - num / 4, 5 + num],
                        [7, 4, 9 + num / 3, 2, 3]])
    line.set_data(newData)
    # This is not working but in docs it is described as a setter
    # annotation.set_position((newData[0][0], newData[1][0]))
    # This works but this is described in docs as getter
    annotation.xytext = (newData[0][0], newData[1][0])
    return line, annotation

anim = animation.FuncAnimation(fig, update, frames=25, init_func=init,
                               interval=200, blit=True)
plt.show()

SO Question where the bug was discovered: Animate points with labels with mathplotlib

@mdboom
Copy link
Member

mdboom commented Aug 26, 2013

I think the issue here is that set_position works only on raw text, not on an annotation. I think it's a matter of making the api more consistent between the two.

@tacaswell
Copy link
Member

It looks like Annotation inherits from both Text and _AnnotationBase both of which maintain location information of the text. The set_position function updates the data structures used by the Text object. They look like they work, but that data is never used in Annotation.draw so it has no effect.

_AnnotationBase is also used as a baseclass for AnnotationBbox.

I would propose pulling xytext and xytextcoords out of _AnnotationBase and making keeping track of where the other end of the annotation is the job of sub-classes.

@tacaswell
Copy link
Member

@alefnula I think this is fixed on master. Please check and if it is not we will reopen.

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

3 participants