>>> import matplotlib
>>> matplotlib.__version__
'0.99.1.1'
运行以下代码:
import matplotlib.pyplot as plt
plt.figure()
ax=plt.axes([.1,.1,.8,.8])
ax.annotate('++++',xy=(.5,.2),xycoords='data')
ax.annotate('aaaa',.4),xycoords='axes fraction')
#ax.annotate('bbbb',.6),xycoords=('data','axes fraction'))
plt.show()
TypeError: 'nonetype' object is not iterable
根据当前的文档,它应该是正确的代码:
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.
关于发生了什么的任何想法?
编辑:
自从第一次发帖以来,我一直在寻找一种解决方法,并发现了另一个问题.当xycoords =’data’时,即使使用clip_on = False,如果annotataion落在轴之外,它仍会被剪裁.以下代码演示了这一点:
import matplotlib.pyplot as plt
plt.figure()
ax=plt.axes([.1,.8])
ax.annotate('cccc',xy=(.3,.5),xycoords='data',clip_on=False)
ax.annotate('dddd',-.1),clip_on=False)
ax.annotate('eeee',xy=(.6,xycoords='axes fraction',clip_on=False)
plt.show()
对于第二个问题,这实际上是记录在案的行为. (clip_on是一个通用的matplotlib文本艺术家kwarg.显然,注释艺术家的行为方式不同.)
来自:http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.annotate
The annotation_clip attribute contols
the visibility of the annotation when
it goes outside the axes area. If
True,the annotation will only be
drawn when the xy is inside the axes.
If False,the annotation will always
be drawn regardless of its position.
The default is None,which behave as
True only if xycoords is”data”.
你需要使用annotation_clip kwarg,而不是:
import matplotlib.pyplot as plt
plt.figure()
ax=plt.axes([.1,annotation_clip=False)
ax.annotate('dddd',annotation_clip=False)
ax.annotate('eeee',annotation_clip=False)
plt.show()
有关更多讨论,请参阅this thread on the matplotlib-users list(并且还注意到annotation_clip kwarg可能在0.99.1上被破坏,因此您可能需要使用那里的解决方法.)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。