Hi,

The Spyder consoles start already with Matplotlib (and pyplot), NumPy and SciPy imported. This means that you can't change the Matplotlib backend anymore since pyplot/pylab module is already imported when the console starts. Remember that you have to set the Matplotlib backend before importing pyplot. This also explains why in a stand alone python console, one not connected to spyder, does work as you expected: there's not a single external module imported upon startup.

To change the Matplotlib backend Spyder uses:
Preferences > Console > External modules > Matplotlib GUI backend

To my understanding (note that I am not a developer), these imports are done in order to get some of Spyders other features to work (e.g. monitor). I assume that, theoretically, you could disable the Matplotlib/pyplot imports upon the startup of a console, but I am not sure where exactly this should be done in the code, and what other consequences this will have.

Maybe a note on Matplotlib backends should be added to the documentation (for instance in the Console section)? I don't mind drafting a proposed change for this somewhere this week.

Regards,
David

On 19/03/12 04:15, ben h wrote:
I want to set the matplotlib backend from within my script. I can do this if I run my script from a shell/terminal, but from Spyder I get an error. 
Here is the full error message:


/usr/local/lib/python2.6/dist-packages/matplotlib-1.0.1-py2.6-linux-x86_64.egg/matplotlib/__init__.py:888: UserWarning: This call to matplotlib.use() has no effect

because the the backend has already been chosen;

matplotlib.use() must be called *before* pylab, matplotlib.pyplot,

or matplotlib.backends is imported for the first time.

if warn: warnings.warn(_use_error_msg)


I searched this list and found this old message that seems related:
https://groups.google.com/d/msg/spyderlib/rAWkNkGWpK0/1fII0P5leowJ


Here is a snippet from my script:

#!/usr/bin/env python

"""
    Bore data plotting routine
"""
# if needed set the backend before importing pyplot:
import matplotlib
matplotlib.use("PS")

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc

... commands ...

--
You received this message because you are subscribed to the Google Groups "spyder" group.
To view this discussion on the web visit https://groups.google.com/d/msg/spyderlib/-/tH5mr59C11MJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/spyderlib?hl=en.

--
You received this message because you are subscribed to the Google Groups "spyder" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/spyderlib?hl=en.

Reply via email to