You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlib.animationasanimation# Create initial datadata=np.array([[1,2,3,4,5], [7,4,9,2,3]])
# Create figure and axesfig=plt.figure()
ax=plt.axes(xlim=(0, 20), ylim=(0, 20))
# Create initial objectsline, =ax.plot([], [], 'r-')
annotation=ax.annotate('A0', xy=(data[0][0], data[1][0]))
annotation.set_animated(True)
definit():
returnline, annotationdefupdate(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 getterannotation.xytext= (newData[0][0], newData[1][0])
returnline, annotationanim=animation.FuncAnimation(fig, update, frames=25, init_func=init,
interval=200, blit=True)
plt.show()
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.
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.
Activity
mdboom commentedon Aug 26, 2013
I think the issue here is that
set_positionworks only on raw text, not on an annotation. I think it's a matter of making the api more consistent between the two.tacaswell commentedon Aug 27, 2013
It looks like
Annotationinherits from bothTextand_AnnotationBaseboth of which maintain location information of the text. Theset_positionfunction updates the data structures used by theTextobject. They look like they work, but that data is never used inAnnotation.drawso it has no effect._AnnotationBaseis also used as a baseclass forAnnotationBbox.I would propose pulling
xytextandxytextcoordsout of_AnnotationBaseand making keeping track of where the other end of the annotation is the job of sub-classes.tacaswell commentedon Nov 27, 2013
@alefnula I think this is fixed on master. Please check and if it is not we will reopen.