22 Dec 2017

Save plot without displaying in Matplotlib

收藏到CSDN网摘
By using Matplotlib, data can be easily plotted in the same way as in Matlab. But sometimes you might need to plot thousands of plots in a bug loop and save those intermediate results. The interactive display could be an issue that makes your machine not only slow but also useless. Someone suggests 'plt.ioff()' to turn off interactive mode. It may work in some cases (according to the feedbacks on Stackoverflow). For me, no magic happened. After searching the internet, the most straightforward solution would be...

use the non-interactive backend like 'Agg' immediately after importing matplotlib. Please note, the backend change has to be happened before any pyplot importing commands. Otherwise, the default backend has been selected and cannot be switched on hot.
import matplotlib
matplotlib.use('Agg')

No comments :

Post a Comment