>> import matplotlib >>> matplotlib._...">

Matplotlib annotate xycoords = ('data', 'axes fraction') => TypeError: object "NoneType" is not iterated

>>> import matplotlib
>>> matplotlib.__version__
'0.99.1.1'

the following code is executed:

import matplotlib.pyplot as plt
plt.figure()
ax=plt.axes([.1, .1, .8, .8])
ax.annotate('++++', xy=(.5,.2), xycoords='data')
ax.annotate('aaaa', xy=(.5,.4), xycoords='axes fraction')
#ax.annotate('bbbb', xy=(.5,.6), xycoords=('data', 'axes fraction'))
plt.show()

but missing ax.annotate gives an error:

TypeError: 'NoneType' object is not iterable

supposedly correct code according to current docs:

From: http://matplotlib.sourceforge.net/users/annotations_guide.html

4. A tuple of two coordinate specification. 
   The first item is for x-coordinate and 
   the second is for y-coordinate. 
   For example,

        annotate("Test", xy=(0.5, 1), xycoords=("data", "axes fraction"))

    0.5 is in data coordinate, and 1 is in normalized axes coordinate.

any ideas on what's going on?

EDIT: starting from the first post, I looked at a workaround and found another problem. When xycoords = 'data', the annotation is still cropped if it goes beyond the axis, even with clip_on = False. Here is the code that demonstrates this:

import matplotlib.pyplot as plt
plt.figure()
ax=plt.axes([.1, .1, .8, .8])
ax.annotate('cccc', xy=(.3, .5), xycoords='data', clip_on=False)
ax.annotate('dddd', xy=(.3,-.1), xycoords='data', clip_on=False)
ax.annotate('eeee', xy=(.6,-.1), xycoords='axes fraction', clip_on=False)
plt.show()
+5
source share
1 answer

matplotlib 1.0 x y annotate. , - . .

. (clip_on matplotlib kwarg. , -.)

: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.annotate

annotation_clip contols , . , xy . False, . None, , xycoords - "".

annotation_clip kwarg, :

import matplotlib.pyplot as plt
plt.figure()
ax=plt.axes([.1, .1, .8, .8])
ax.annotate('cccc', xy=(.3, .5), xycoords='data', annotation_clip=False)
ax.annotate('dddd', xy=(.3,-.1), xycoords='data', annotation_clip=False)
ax.annotate('eeee', xy=(.6,-.1), xycoords='axes fraction', annotation_clip=False)
plt.show()

. matplotlib ( , annotation_clip kwarg 0.99.1, .)

+4

All Articles