Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spyder console turn off interactive matplotlib plotting

I'm doing some plotting using matplotlib in the Spyder GUI. I just want these figures to be made quietly in the background and save to a file path. I'm running my scripts from the console and while the figures get made and saved fine, I can't stop them all popping up in their own little windows (there are about 240 graphs so clearly this is causing memory issues).

I have scattered the command plt.ioff() generously throughout the script but it doesn't seem to help

Any ideas? Cheers

like image 252
WRJ Avatar asked Dec 02 '16 09:12

WRJ


People also ask

Are matplotlib plots interactive?

Even with so many choices, Matplotlib , fondly known as the Grandfather of python visualization packages remains a favorite for many. The lack of interactiveness, however, remains a bottleneck. So, workarounds have been devised to include interactivity via some third-party libraries.

What is interactive mode in matplotlib?

Matplotlib can be used in an interactive or non-interactive modes. In the interactive mode, the graph display gets updated after each statement. In the non-interactive mode, the graph does not get displayed until explicitly asked to do so.

Where is the plots pane Options menu in Spyder?

The options menu in the top right of the Plots pane offers several ways to customize how your plots are displayed.


1 Answers

Figures should not be popping up if you use a non-interactive backend. Put this at the very beginning of the script:

import matplotlib as mpl
mpl.use('Agg')

You might run into memory issues anyway if you create many figures without closing them.

like image 103
Stop harming Monica Avatar answered Oct 23 '22 13:10

Stop harming Monica