4

I would like to save my figures to disk without rendering them on the screen and without having to change my rendering backend.

I tried the instructions in here, namely avoiding calling fig.show() nor fig.draw() and just calling fig.savefig, but I noticed that the mere statement fig = plt.figure() already opens a figure on the screen.

How can I save a figure to disk without having to render it, and without having to change my backend?

Community
  • 1
  • 1
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
  • 2
    `plt.ioff()` Why don't you just use a non-interactive backend? And almost all of the `plt.*` commands have an implicit `plt.draw()` in them so you _are_ calling it. – tacaswell Aug 01 '13 at 02:31
  • Thanks @tcaswell I realize I had an `ion()` on my code. If you write that as an answer I will accept it. – Amelio Vazquez-Reina Aug 01 '13 at 02:37

1 Answers1

3

pyplot has an interactive functionality which will automatically call draw() after most plt.* calls for you.

draw is not automatically called if you don't go through the state machine interface (ex gca().plot(...) would not automatically redraw, but plt.plot(...) would).

See the code, the important function in draw_if_interactive.

This can be turn off via plt.ioff() or by not calling plt.ion() (ipython --pylab automatically turns it on for you).

doc

tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • At least in some recent versions of Matplotlib, it is not true that "`draw()` is automatically called after each call" in interactive mode, so this should be taken with a grain of salt. There are [interesting points](http://stackoverflow.com/questions/6130341/exact-semantics-of-matplotlibs-interactive-mode-ion-ioff) on this in one of my StackOverflow questions. – Eric O. Lebigot Aug 01 '13 at 05:15