Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cairo Backend: Can't convert 'bytes' object to str implicitly on Python3 #2903

Closed
vmarkovtsev opened this issue Mar 17, 2014 · 5 comments · Fixed by #2906
Closed

Cairo Backend: Can't convert 'bytes' object to str implicitly on Python3 #2903

vmarkovtsev opened this issue Mar 17, 2014 · 5 comments · Fixed by #2906
Milestone

Comments

@vmarkovtsev
Copy link
Contributor

When trying to use "cairo" backend with text labels on Python3, I get

  File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 571, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1448, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 2192, in print_figure
    **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_cairo.py", line 442, in print_png
    self.figure.draw (renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1057, in draw
    func(*args)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 2076, in draw
    a.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1108, in draw
    tick.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 249, in draw
    self.label1.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/text.py", line 584, in draw
    ismath=ismath, mtext=self)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_cairo.py", line 218, in draw_text
    ctx.show_text(s)
TypeError: Can't convert 'bytes' object to str implicitly

Other backends work fine. This seems to be a pretty typical bytes vs. str Python3 bug.

I have no cairocffi installed and cairo.version_info is (1, 10, 0).

@tacaswell tacaswell added this to the v1.4.0 milestone Mar 17, 2014
@tacaswell
Copy link
Member

Looks like more side effects of the switch from 2to3 -> six.

@vmarkovtsev
Copy link
Contributor Author

I would say that quick and dirty fix to ctx.show_text(s.decode()) makes the backend work correct. I am just not sure that fixing symptoms is a right thing.

@tacaswell
Copy link
Member

That seems like the correct fix to me. Can you put in a PR with that fix and we will see what @mdboom thinks.

@mdboom
Copy link
Member

mdboom commented Mar 18, 2014

Can you provide a complete script that reproduces the problem? I'm not sure why bytes are getting in there in the first place -- I would have expected it to be Unicode all the way down.

@vmarkovtsev
Copy link
Contributor Author

import matplotlib
matplotlib.use("cairo")
import matplotlib.pyplot as pp

if __name__ == "__main__":
    figure = pp.figure("Test Cairo")
    figure.clf()
    main_axes = figure.add_axes([0, 0, 1, 1])
    main_axes.cla()
    figure.text(label="Test", s="100", x=0.1, y=0.9)
    figure.canvas.draw()
    pp.savefig("/tmp/test_cairo.png")

python3 test.py throws TypeError whereas python test.py works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants