Question

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.

Was it helpful?

Solution

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top