1

I am using python and matplotlib.pyplot to produce various plots.

I am not making the plots show(), I am instead saving them using matplotlib.pyplot.savefig() and matplotlib.pyplot.clf()

As the code runs, X11 brings up a cascade of blank windows - 1 for every plot that I save - until the code has finished.

The code works and my plots are saved as desired, but the blank windows which appear while the code is running are annoying.

How can I stop this please?


Edit:

This happens on all of my code. I guess the only relevant code is what I already put:

matplotlib.pyplot.savefig('{0}.png' .format(index))
matplotlib.pyplot.clf()

Okay, after further invetigation, my problem only occurs if I have imported Gpy. Here is a simple example that shows my issue:

import numpy as np
import GPy
import matplotlib.pyplot as plt

x = np.arange(0,10,1)

for i in range(10):
    fig = plt.figure()
    plt.plot(x)
    plt.savefig('test_{0}.png' .format(i))
   plt.clf()

Of course now, I can just remove the import Gpy line if I don't need it.

My version of python is 2.7.3

3
  • It's not clear to me, why you are calling plt.clf at the end. Isn't plt.close what you actually want to do? Commented Feb 22, 2015 at 11:53
  • 3
    Which version of matplotlib are you using? Could you increase the size of your code example to show a minimal, complete and verifiable example that produces the undesired behavior on your side, but such that we can also run it, to verify? Commented Feb 22, 2015 at 12:07
  • Also consider using the OO interface and a non-interactive backend (ex Agg) Commented Feb 23, 2015 at 3:03

1 Answer 1

1

There's a pretty good chance that GPy is somehow turning on matplotlibs interactive mode. You can turn it off again using

plt.ioff()

Hopefully that works

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.