SourceForge logo
SourceForge logo
Menu

Re: [matplotlib-devel] Cairo backend prospects

From: Darren D. <dd...@co...> - 2007年01月15日 11:36:28
On Monday 15 January 2007 12:16 am, Steve Chaplin wrote:
> On Thu, 2007年01月11日 at 00:01 -0700, Fernando Perez wrote:
> > On 1/10/07, Steve Chaplin <ste...@ya...> wrote:
> > > On Mon, 2007年01月08日 at 11:24 -0500, Darren Dale wrote:
> > > > I had to alter the following lines from backend_gtkcairo, from
> > > >
> > > > import matplotlib.backends.backend_cairo as be_cairo
> > > > from matplotlib.backends.backend_gtk import *
> > > >
> > > > to
> > > >
> > > > import backend_cairo as be_cairo
> > > > from backend_gtk import *
> > > >
> > > > in order to prevent the following traceback:
> > > >
> > > > Traceback (most recent call last):
> > > > File "/usr/bin/ipython", line 27, in ?
> > > > IPython.Shell.start().mainloop()
> > > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line
> > > > 1034, in start
> > > > return shell(user_ns = user_ns)
> > > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line
> > > > 945, in __init__
> > > > shell_class=MatplotlibMTShell)
> > > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line
> > > > 622, in __init__
> > > > on_kill=[mainquit])
> > > > File "/usr/lib64/python2.4/site-packages/IPython/ipmaker.py", line
> > > > 90, in make_IPython
> > > > embedded=embedded,**kw)
> > > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line
> > > > 506, in __init__
> > > > user_ns,b2 = self._matplotlib_config(name,user_ns)
> > > > File "/usr/lib64/python2.4/site-packages/IPython/Shell.py", line
> > > > 397, in _matplotlib_config
> > > > from matplotlib import backends
> > > > File
> > > > "/usr/lib64/python2.4/site-packages/matplotlib/backends/__init__.py",
> > > > line 55, in ?
> > > > new_figure_manager, draw_if_interactive, show = pylab_setup()
> > > > File
> > > > "/usr/lib64/python2.4/site-packages/matplotlib/backends/__init__.py",
> > > > line 23, in pylab_setup
> > > > globals(),locals(),[backend_name])
> > > >
> > > > File
> > > > "/usr/lib64/python2.4/site-packages/matplotlib/backends/backend_gtkca
> > > >iro.py", line 11, in ?
> > > > import matplotlib.backends.backend_cairo as be_cairo
> > > > AttributeError: 'module' object has no attribute 'backends'
> > >
> > > The original matplotlib code is correct, you should be editing IPython
> > > and correcting their bug!
> >
> > Well, I'd be delighted to correct the ipython bug, if only I
> > understood exactly what the problem was... As far as I can see, that
> > code in ipython is simply calling
> >
> > # Initialize matplotlib to interactive mode always
> > import matplotlib
> > from matplotlib import backends
> >
> > inside a function (the _matplotlib_config method). I don't see a bug
> > in that, but if you provide some pointers, I'll be happy to fix any
> > issues that are on ipython's side of the fence.
>
> Darren reported a "bug" in backend_gtkcairo.py which he has "fixed". My
> view is that the lines
> from matplotlib.backends import backend_cairo
> from matplotlib.backends.backend_gtk import *
> work fine when called from the Python prompt. They are using the
> absolute package path and are correct and should not be "fixed" to use
> relative imports (which is bad style). So if there is a bug it is
> elsewhere and from the traceback it looked like ipython is involved.
>
> The traceback shows that this code is being executed
> # a hack to keep old versions of ipython working with mpl
> if 'IPython.Shell' in sys.modules:
> new_figure_manager, draw_if_interactive, show = pylab_setup()
>
> which is ipython-specific code.
> I don't usually use IPython, but I installed it today and ran a few
> simple matplotlib plots with the GTKCairo backend and they worked OK! So
> I can't offer more info, perhaps Darren can produce a minimal test case
> to isolate the problem.
They work ok now, after changing the import statement so that it doesnt rename 
backend_cairo to be_cairo in the gtkcairo namespace. I can't think of a more 
minimal example than the one I already provided: starting IPython without the 
pylab flag and importing matplotlib.backends.backend_gtkcairo. I looked at 
this for a couple hours last week, and was not able to determine whether it 
was an IPython bug or a matplotlib bug that is exposed by IPython's magic. I 
do agree that the absolute path imports are correct and are not the source of 
the problem. Since a workaround has been committed, I don't think I should 
spend more time on this issue (unless another problem emerges).
Darren

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /