The solution is to setup a figure/axis in main.py and then pass the axis handle to each module. As a minimal example,
import matplotlib.pyplot as plt
import numpy as np
#from mod import plotsomefunction
#from diffrentmod import plotsomeotherfunction
def plotsomefunction(ax, x):
return ax.plot(x, np.sin(x))
def plotsomeotherfunction(ax, x):
return ax.plot(x,np.cos(x))
fig, ax = plt.subplots(1,1)
x = np.linspace(0,np.pi,1000)
l1 = plotsomefunction(ax, x)
l2 = plotsomeotherfunction(ax, x)
plt.show()
where the functions represent modules.
Alternatively, you could just create a figure in main and add it to the current axis in each module with plt.sca
. This seems like a much less robust solution.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…