matplotlib backends - WXAgg vs. WX

Hi all,
I'd like to ask a probably basic qustion about backends in matplotlib
- specifically with regard to WXAgg and WX.
What are the differences of the two, and what are the supposed
usecases, and maybe restrictions for them?

Using matplotlib/pylab pylab in a rather basic way I encountered
problems with both backends and would like to clarify the differences
before i try to find a fix.

using wxAgg I am not able to display unicode text (some accents,
non-latin scripts etc. e.g. in pylab.title(...) and otherwhere .
Just changing:
matplotlib.use('WXAgg')
to
matplotlib.use('WX')
seemed to fix this, and the graph gui also looks more consistent with
my wxPython app.

However, using the current wxPython 2.9.2.1. (python 2.7.2, Win 7,
Czech) I see a more serious bug in the wx-backend (basically failing
to display the graph at all
(cf. http://sourceforge.net/mailarchive/message.php?msg_id=27902016 ),
which doesn't apply for WXAgg.

Coud someone maybe provide some hints, where I should look into to
understand the backend differences better?

Thanks in advance,

Regards,
    Vlastimil Brom

Hi all,
I'd like to ask a probably basic qustion about backends in matplotlib
- specifically with regard to WXAgg and WX.
What are the differences of the two, and what are the supposed
usecases, and maybe restrictions for them?

http://matplotlib.sourceforge.net/faq/installing_faq.html#backends

WXAgg is WX for window and widgets, but with all figure rendering done using the Agg library to generate an image which is then displayed as such by WX. There is the same sort of pair for gtk: gtkagg and plain gtk. Only the *agg interactive backends are fully supported; it is expected that not everything will work with the non-agg interactive backends, and every now and then there is discussion of whether they should be eliminated for that reason. Their only advantage, as far as I know, is that under some circumstances, such as working remotely with X on a slow link, the non-agg backends may be faster.

Using matplotlib/pylab pylab in a rather basic way I encountered
problems with both backends and would like to clarify the differences
before i try to find a fix.

using wxAgg I am not able to display unicode text (some accents,
non-latin scripts etc. e.g. in pylab.title(...) and otherwhere .

This is surprising; in general, unicode works with the *agg backends.
Maybe plain WX is finding some fonts that WXAgg is not finding?

Eric

···

On 08/13/2011 01:11 PM, Vlastimil Brom wrote:

Just changing:
matplotlib.use('WXAgg')
to
matplotlib.use('WX')
seemed to fix this, and the graph gui also looks more consistent with
my wxPython app.

However, using the current wxPython 2.9.2.1. (python 2.7.2, Win 7,
Czech) I see a more serious bug in the wx-backend (basically failing
to display the graph at all
(cf. http://sourceforge.net/mailarchive/message.php?msg_id=27902016 ),
which doesn't apply for WXAgg.

Coud someone maybe provide some hints, where I should look into to
understand the backend differences better?

Thanks in advance,

Regards,
     Vlastimil Brom

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy
to use, easy to manage, easy to install, easy to extend.
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

2011/8/14 Eric Firing <efiring@...202...>:

···

On 08/13/2011 01:11 PM, Vlastimil Brom wrote:

Hi all,
I'd like to ask a probably basic qustion about backends in matplotlib
- specifically with regard to WXAgg and WX.
What are the differences of the two, and what are the supposed
usecases, and maybe restrictions for them?

http://matplotlib.sourceforge.net/faq/installing_faq.html#backends

WXAgg is WX for window and widgets, but with all figure rendering done
using the Agg library to generate an image which is then displayed as
such by WX. There is the same sort of pair for gtk: gtkagg and plain
gtk. Only the *agg interactive backends are fully supported; it is
expected that not everything will work with the non-agg interactive
backends, and every now and then there is discussion of whether they
should be eliminated for that reason. Their only advantage, as far as I
know, is that under some circumstances, such as working remotely with X
on a slow link, the non-agg backends may be faster.

Using matplotlib/pylab pylab in a rather basic way I encountered
problems with both backends and would like to clarify the differences
before i try to find a fix.

using wxAgg I am not able to display unicode text (some accents,
non-latin scripts etc. e.g. in pylab.title(...) and otherwhere .

This is surprising; in general, unicode works with the *agg backends.
Maybe plain WX is finding some fonts that WXAgg is not finding?

Eric

Thanks for the reference and for the important info, that only wxagg
is considered fully supported as opposed to wx backend.
It appears, that in the current state, using the latest wxpython
2.9.2.1, it is indeed unusable, as no graph canvas is displayed at all
(at least on my setup - win 7, py-2.7), cf.:

####################################################

#! Python
# -*- coding: utf-8 -*-

import wxversion
# wxversion.select('2.9.1') # 2.9.1.1 # plot ok
wxversion.select('2.9.2') # 2.9.2.1 # invalid "transparent" canvas
without any graph content
import wx

import matplotlib
matplotlib.use('WX')
import pylab

pylab.plot(range(3), range(3))
pylab.show()

####################################################

Regarding wxagg, it seems, that the suggestion about unsuitable fonts
being used was correct;
after setting the font to Arial, adapted from:
http://matplotlib.sourceforge.net/examples/api/font_family_rc.html
all the characters in the title are displayed ok.

####################################################
#! Python
# -*- coding: utf-8 -*-

import wxversion
wxversion.select('2.9.2') # 2.9.2.1
import wx

# setting the font to Arial - the title is displayed completely;
# with the default font only the "latin-1" characters are shown
from matplotlib import rcParams
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Arial'] + rcParams['font.sans-serif']
#

import matplotlib
matplotlib.use('WXAgg')
import pylab

pylab.plot(range(3), range(3))
pylab.title(u"abcd áčďéěíňóřšťúůýž äöüß ê αβγδ абвгд אבגד xyz")
pylab.show()

####################################################
(using python 2.7.2, MPL 1.0.1; Win 7, Czech)

Is there maybe some machanism available in matplotlib, which would
select the appropriate font for the given characters? (Like in wx or,
even more powerful in tk?) Or is it the expected way to set the
suitable font individually, as only the font list in rcParams are
tried sequentially - regardless of the character support?

Regards,
   vbr

That's correct: matplotlib doesn't currently do this. It renders a particular string of text with a single font and does not do font substitution for characters that are not in that font. The best practice is to use a font that contains the full set of characters, such as Arial or Deja Vu as you've discovered.

There a lot of other i18n shortcomings to the way matplotlib supports text (such as a lack of bidi support). That's a large wheel to reinvent, so the solution would involve using a third-party text layout library such as pango, but I know there is licensing friction against that. It may be worth revisiting that at some point.

Mike

···

On 08/14/2011 11:28 AM, Vlastimil Brom wrote:

####################################################

Regarding wxagg, it seems, that the suggestion about unsuitable fonts
being used was correct;
after setting the font to Arial, adapted from:
http://matplotlib.sourceforge.net/examples/api/font_family_rc.html
all the characters in the title are displayed ok.

####################################################
#! Python
# -*- coding: utf-8 -*-

import wxversion
wxversion.select('2.9.2') # 2.9.2.1
import wx

# setting the font to Arial - the title is displayed completely;
# with the default font only the "latin-1" characters are shown
from matplotlib import rcParams
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Arial'] + rcParams['font.sans-serif']
#

import matplotlib
matplotlib.use('WXAgg')
import pylab

pylab.plot(range(3), range(3))
pylab.title(u"abcd áčďéěíňóřšťúůýž äöüß ê αβγδ абвгд אבגד xyz")
pylab.show()

####################################################
  (using python 2.7.2, MPL 1.0.1; Win 7, Czech)

Is there maybe some machanism available in matplotlib, which would
select the appropriate font for the given characters? (Like in wx or,
even more powerful in tk?) Or is it the expected way to set the
suitable font individually, as only the font list in rcParams are
tried sequentially - regardless of the character support?

2011/8/15 Michael Droettboom <mdroe@...86...>:

···

On 08/14/2011 11:28 AM, Vlastimil Brom wrote:

...
Is there maybe some mechanism available in matplotlib, which would
select the appropriate font for the given characters? (Like in wx or,
even more powerful in tk?) Or is it the expected way to set the
suitable font individually, as only the font list in rcParams are
tried sequentially - regardless of the character support?

That's correct: matplotlib doesn't currently do this. It renders a
particular string of text with a single font and does not do font
substitution for characters that are not in that font. The best
practice is to use a font that contains the full set of characters, such
as Arial or Deja Vu as you've discovered.

There a lot of other i18n shortcomings to the way matplotlib supports
text (such as a lack of bidi support). That's a large wheel to
reinvent, so the solution would involve using a third-party text layout
library such as pango, but I know there is licensing friction against
that. It may be worth revisiting that at some point.

Mike

Thanks for the confirmation, I'll stick with this apporoach, as I
didn't manage to fix the code for wx backend on the newest version
(cf. above). Given the status of the non-Agg backends it might be more
appropriate.

Regards,
   vbr