如何解决在 matplotlib 中的图形之间移动绘图
我想使用外部函数返回的轴句柄将来自该轴的绘图对象放置在我选择的位于另一个图形中的子图中。不能修改外部函数的格式。 下面的代码是一个虚拟示例,表示我正在使用的代码的结构。
我希望有一个内置函数来执行此操作,例如 set_figure() 但我找不到。任何帮助表示赞赏。
import matplotlib.pyplot as plt
def myfunc():
plt.figure()
plt.text(0.5,0.5,s='plot from\nexternal function')
return plt.gca()
plt.subplot(311)
plt.text(0.5,s='subplot 1')
plt.subplot(312)
plt.text(0.5,s='subplot 2')
plt.subplot(313)
ax = myfunc()
# how can I make the plot generated by myfunc appear in the third subplot
# and close the figure from the external function so it does not show?
plt.show()
所需的输出如下所示:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。