I'm performing a simulation which requires some time so I thought to have a real time plot which gets updated at each step so that I can track the most useful information and check if everything is going well. I'm using this function which relies on matplotlib.pyplot
:
def monitor(FSI_config,tracking):
print("Tracking...")
it = [];
i=0;
while i < len(tracking.tracking_vel):
it.append(i)
i=i+1
plt.figure(1)
plt.subplot(211) # the first subplot in the first figure
line1, = plt.plot(it, tracking.tracking_pos, linewidth=2.0,
color='r', linestyle='--', marker='.', markersize=15,
markeredgecolor='k', markerfacecolor='k')#,
label=r'$C_D$')
plt.subplot(212) # the second subplot in the first figure
line1, = plt.plot(it, tracking.tracking_vel, linewidth=2.0,
color='r', linestyle='--', marker='.', markersize=15,
markeredgecolor='k', markerfacecolor='k')#, label=r'$C_L$')
plt.show()
So, the function monitor
is executed each step of the simulation and plots the values contained in tracking
. Important to underline is that tracking
, at each step, contains all the values to be plotted (each new value is appended at the end of the new step before entering monitor
) Now, beyond the details of the script, the true point is that once the function executes plt.show() the whole simulation stops until the figure is closed. Is there a way to keep the figure in the background, while the script goes ahead, and automatically close it just before the new one (at the following step) is plotted with updated values?
Thanks for the help
PS: the question is different than real-time plotting in while loop with matplotlib as here we are talking about a self updating plot and not a plot inside a for/while loop.