这是我的代码:
import matplotlib.pyplot as plt
plt.figure(1) # the first figure
plt.subplot(211) # the first subplot in the first figure
plt.plot([1, 2, 3])
plt.subplot(212) # the second subplot in the first figure
plt.plot([4, 5, 6])
plt.figure(2) # a second figure
plt.plot([4, 5, 6]) # creates a subplot(111) by default
plt.text(.5,1.5,'211',figure = 211) #tring to add text in previous subplot
plt.figure(1) # figure 1 current; subplot(212) still current
plt.subplot(211) # make subplot(211) in figure1 current
plt.title('Easy as 1, 2, 3') # subplot 211 title
错误:
Traceback (most recent call last):
File "C:/Users/ezhou/Desktop/python/test3.py", line 11, in <module>
plt.text(.5,1.5,'211',figure = 211)
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 3567, in text
ret = gca().text(x, y, s, fontdict=fontdict, withdash=withdash, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 619, in text
self._add_text(t)
File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 1720, in _add_text
self._set_artist_props(txt)
File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 861, in _set_artist_props
a.set_figure(self.figure)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 640, in set_figure
raise RuntimeError("Can not put single artist in "
RuntimeError: Can not put single artist in more than one figure
我试图理解matplotlib.text.text()类中的kwargs“figure”,但它总是回答“不能将单个艺术家放在多个图形中”。所以我对如何使用这个“数字”kwarg感到困惑。有人能给我一些建议吗?谢谢!
我完全被困在这上面了。我的理解是
matplotlib.figure
用于在GUI中嵌入一个图,然后能够在保持帧不变的情况下更新信息?。这将(在python 2.7上,我认为它是python 3中的tkinter
)无错误地运行并生成相同的图。但是我完全不知道为什么他们提供了使用plt
更新这个图上的文本的选项,而文本没有显示出来。我明天会再看一遍,但我很高兴有人能在这段时间纠正我,因为文档很混乱。不应将figure作为kwarg传递,而应使用figure(或Axes)实例的文本方法。示例:
请注意坐标是相对的(0,1)。
如果你发现matplotlib不必要地复杂(我也这么认为),你可能想看看Plotly
相关问题 更多 >
编程相关推荐