如何在同一窗口中绘制来自不同功能的2个子图(图)? [英] How to plot 2 subplots from different functions in the same window(figure)?

查看:28
本文介绍了如何在同一窗口中绘制来自不同功能的2个子图(图)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于特定的原因,我有两个函数,每个函数在两个不同的窗口中创建一个图.是否可以在一个窗口中统一这两个图,而不统一功能?谢谢!

for specific reasons I have two functions, each of them creates a plot in two different windows. Is it possible to unify this two plots in one window, without unifying the functions? thanks!

我有2个涉及的函数和一个数据库:file1.py中的函数1绘制2d线图:

edit: I have 2 involved functions and a database: function 1 in file1.py plots a 2d-line plot:

plt.figure("TEST12") 
ax=plt.subplot(111)
ax.plot(array[:,10])

在file2.py中,还有另一个函数,该函数绘制了填充的轮廓:

In file2.py theres my other function, which plots a filled contour:

plt.figure("TEST13")
ax = plt.subplot(111)
ax.contourf(x,y,data)
plt.gca().set_aspect('equal')

如果我像往常一样使用 plt.show,结果是 2 个不同的窗口.

If I use plt.showas usual, the result are 2 different windows.

推荐答案

重构你的函数,将一个 Axes 对象作为参数进行绘制:

Re-factor your function to take an Axes object to draw to as an argument:

def fun1(ax):
    ax.plot(range(5))

def fun2(ax):
    ax.plot(range(5)[::-1])


fig, ax = plt.subplots(1, 1)

fun1(ax)
fun2(ax)

plt.draw()

这篇关于如何在同一窗口中绘制来自不同功能的2个子图(图)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆