python-RuntimeError:使用matplotlib 1.5时,不能将单个艺术家放在一个以上的图中
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-RuntimeError:使用matplotlib 1.5时,不能将单个艺术家放在一个以上的图中,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2056字,纯文字阅读大概需要3分钟。
内容图文
![python-RuntimeError:使用matplotlib 1.5时,不能将单个艺术家放在一个以上的图中](/upload/InfoBanner/zyjiaocheng/683/38c9b25b90d8412796d6f387ce18f271.jpg)
这是我的代码:
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’,但它总是会回答“不能将单个艺术家放在一个以上的图中”.因此,我对如何使用此“数字”花样感到困惑.谁能给我一些建议?谢谢!
解决方法:
您不应该将图形作为虚假参数传递,而应使用图形(或Axes)实例的文本方法.例:
import matplotlib.pyplot as plt
fig1, fig2 = plt.figure(1), plt.figure(2)
sp1, sp2 = fig1.add_subplot(211), fig2.add_subplot(211)
sp1.plot([1, 2, 3])
sp2.plot([0, 1, 3])
fig1.text(.5, .3, 'whole figure')
sp2.text(.5, .5, 'subplot')
请注意,坐标是相对的(0,1).
附注:如果您发现matplotlib不必要地复杂(就像我一样),则不妨查看一下Plotly
内容总结
以上是互联网集市为您收集整理的python-RuntimeError:使用matplotlib 1.5时,不能将单个艺术家放在一个以上的图中全部内容,希望文章能够帮你解决python-RuntimeError:使用matplotlib 1.5时,不能将单个艺术家放在一个以上的图中所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。