문제

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!

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])

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')

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

도움이 되었습니까?

해결책

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()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top