Matplotlib can't suppress figure window
13,145
Perhaps just clear the axis, for example:
plt.savefig("static/data.png")
plt.close()
will not plot the output in inline mode. I can't work out if is really clearing the data though.
Author by
Magic_Matt_Man
Updated on July 23, 2022Comments
-
Magic_Matt_Man almost 2 years
I'm having trouble with matplotlib insisting on displaying a figure wnidow even when I haven't called show().
The function in question is:
def make_plot(df): fig, axes = plt.subplots(3, 1, figsize=(10, 6), sharex=True) plt.subplots_adjust(hspace=0.2) axes[0].plot(df["Date_Time"], df["T1"], df["Date_Time"], df["T2"]) axes[0].set_ylabel("Temperature (C)") axes[0].legend(["T1", "T2"], bbox_to_anchor=(1.12, 1.1)) axes[1].semilogy(df["Date_Time"], df["IGP"], df["Date_Time"], df["IPP"]) axes[1].legend(["IGP", "IPP"], bbox_to_anchor=(1.12, 1.1)) axes[1].set_ylabel("Pressure (mBar)") axes[2].plot(df["Date_Time"], df["Voltage"], "k") axes[2].set_ylabel("Voltage (V)") current_axes = axes[2].twinx() current_axes.plot(df["Date_Time"], df["Current"], "r") current_axes.set_ylabel("Current (mA)") axes[2].legend(["V"], bbox_to_anchor=(1.15, 1.1)) current_axes.legend(["I"], bbox_to_anchor=(1.14, 0.9)) plt.savefig("static/data.png")
where df is a dataframe created using pandas. This is supposed to be in the background of a web server, so all I want is for this function to drop the file in the directory specified. However, when it executes it does this, and then pulls up a figure window and gets stuck in a loop, preventing me from reloading the page. Am I missing something obvious?
EDIT: Forgot to add, I am running python 2.7 on Windows 7, 64 bit.