Starting from matplotlib version 3.3.0 you can do the following at the beginning
import matplotlib.pyplot as plt plt.rcParams["figure.raise_window"]=False
Source: https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.3.0.html#rcparams-for-controlling-default-raise-window-behavior
Credit to https://github.com/matplotlib/matplotlib/issues/22939#issuecomment-1113696066