Fernando Perez wrote:
On Mon, Jun 9, 2008 at 10:16 AM, Eric Firing <[EMAIL PROTECTED]> wrote:
Please try now, with r5435 or later. There is still the underlying
puzzle to be solved before all this can be cleaned up, but I think the
basic functionality is back.
Eric: in Shell,py, around line 1167, you'll find this code:
backends = {'gthread' : 'GTKAgg',
'wthread' : 'WXAgg',
'qthread' : 'QtAgg',
'q4thread' :'Qt4Agg',
'tkthread' :'TkAgg',
}
That is used to SET the rcParams['backend'] value. I don't know if
that can cause issues.
No, that is OK with old or svn versions of mpl.
But more importantly, I think the problem you see comes from this code
(just a bit later in the same file):
else:
backend = matplotlib.rcParams['backend']
if backend.startswith('GTK'):
th_mode = 'gthread'
elif backend.startswith('WX'):
th_mode = 'wthread'
elif backend.startswith('Qt4'):
th_mode = 'q4thread'
elif backend.startswith('Qt'):
th_mode = 'qthread'
else:
# Any other backend, use plain Tk
th_mode = 'tkthread'
return mpl_shell[th_mode]
Yes, I was looking for this sort of thing but managed to miss it
yesterday. This is where the problem is. The workaround that I have in
mpl svn now is to simply retain the mixed cases (although the input and
checking are completely case-insensitive). My suggested change for
ipython, so that some day mpl would not need to retain the mixed cases,
is in the attached diff against ipython svn. Fairly quick checks
against mpl svn, mpl svn with all lower case, and mpl maintenance branch
indicated that this change would be backwards and forwards compatible,
so long as mpl retains rcsetup.validate_backend().
It also makes it so that you could go to lower case in:
backends = {'gthread' : 'GTKAgg',
'wthread' : 'WXAgg',
'qthread' : 'QtAgg',
'q4thread' :'Qt4Agg',
'tkthread' :'TkAgg',
}
and this should also be backwards and forwards compatible; by using
validate_backend when setting the backend, one ensures that rcParams
gets a form that the particular version of mpl is happy with.
You might be able to use matplotlib.use(backends[th_mode]) to replace
the following in my suggested diff, provided you have not already
performed some magic that would foil the sys.modules checking done by
matplotlib.use():
backend = mrcsetup.validate_backend(backends[th_mode])
matplotlib.rcParams['backend'] = backend
The rationale for using "matplotlib.use" and "matplotlib.get_backend" is
that they can take advantage of validation that is not available when
you directly get and set the rcParams value. On the other hand there is
some appeal in the directness of going straight to/from rcParams.
Anyway, regardless of whether you decide to make any changes in ipython,
thanks for solving the puzzle.
Eric
IPython does an explicit check on the names of the backends with that
exact capitalization. I could add a .lower() call to the line that
starts:
backend = matplotlib.rcParams['backend'].lower()
and change the .startswith() calls to do all lowercase checks. Could
you see if that helps? That would make the fix backwards compatible.
Cheers,
f
Index: IPython/Shell.py
===================================================================
--- IPython/Shell.py (revision 3108)
+++ IPython/Shell.py (working copy)
@@ -1154,6 +1154,7 @@
try:
import matplotlib
+ import matplotlib.rcsetup as mrcsetup
except ImportError:
error('matplotlib could NOT be imported! Starting normal
IPython.')
return IPShell
@@ -1163,16 +1164,17 @@
# threading backend, else it's auto-selected from the rc file
if special_opts:
th_mode = special_opts.pop()
- matplotlib.rcParams['backend'] = backends[th_mode]
+ backend = mrcsetup.validate_backend(backends[th_mode])
+ matplotlib.rcParams['backend'] = backend
else:
- backend = matplotlib.rcParams['backend']
- if backend.startswith('GTK'):
+ backend = matplotlib.get_backend().lower()
+ if backend.startswith('gtk'):
th_mode = 'gthread'
- elif backend.startswith('WX'):
+ elif backend.startswith('wx'):
th_mode = 'wthread'
- elif backend.startswith('Qt4'):
+ elif backend.startswith('qt4'):
th_mode = 'q4thread'
- elif backend.startswith('Qt'):
+ elif backend.startswith('qt'):
th_mode = 'qthread'
else:
# Any other backend, use plain Tk
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel