Skip to content

Loading…

Update lib/matplotlib/backends/backend_cairo.py #1687

Merged
merged 1 commit into from

4 participants

@burrbull

python version control in _draw_mathtext as in draw_text

@dmcdougall
Matplotlib Developers member

Thanks for your time to create a PR, @burrbull. I have one question, is there anything wrong with encoding unicode in python 3.x? Since strings are unicode by default in python 3.x, isn't s.encode("utf-8") a no-op?

@mdboom
Matplotlib Developers member

s.encode('utf-8') converts a Unicode string to a byte string (encoded in utf-8). My understanding is that Cairo on Python 2.x expects a utf-8-encoded byte string to be passed to it, whereas under Python 3.x it expects an actual Unicode string. So this fix makes sense to me.

@efiring efiring merged commit cb419a9 into matplotlib:master

1 check was pending

Details default The Travis build is in progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2013
  1. @burrbull
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/matplotlib/backends/backend_cairo.py
View
5 lib/matplotlib/backends/backend_cairo.py
@@ -220,7 +220,10 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
size = fontsize * self.dpi / 72.0
ctx.set_font_size(size)
- ctx.show_text(s.encode("utf-8"))
+ if sys.version_info[0] < 3:
+ ctx.show_text (s.encode("utf-8"))
+ else:
+ ctx.show_text (s)
ctx.restore()
for ox, oy, w, h in rects:
Something went wrong with that request. Please try again.