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

GTK3Cairo backend: "TypeError: Can't convert 'bytes' object to str implicitly" with python 3, when using log scale #4514

Closed
count0 opened this issue Jun 11, 2015 · 7 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@count0
Copy link

count0 commented Jun 11, 2015

I'm getting the following error with the GTK3Cairo backend, when using python 3.

Self-contained example code:

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

if __name__ == "__main__":
    figure = pp.figure("Test Cairo")
    figure.clf()
    ax = figure.add_axes([0, 0, 1, 1])
    ax.plot(range(1, 10), range(1, 10))
    ax.set_xscale("log")
    ax.set_yscale("log")
    pp.savefig("/tmp/test_cairo.pdf")

Error:

Traceback (most recent call last):
  File "gtk3_bug.py", line 12, in <module>
    pp.savefig("/tmp/test_cairo.pdf")
  File "/usr/lib/python3.4/site-packages/matplotlib/pyplot.py", line 577, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/figure.py", line 1476, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 2211, in print_figure
    **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/backends/backend_cairo.py", line 446, in print_pdf
    return self._save(fobj, 'pdf', *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/backends/backend_cairo.py", line 510, in _save
    self.figure.draw (renderer)
  File "/usr/lib/python3.4/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/figure.py", line 1085, in draw
    func(*args)
  File "/usr/lib/python3.4/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/axes/_base.py", line 2110, in draw
    a.draw(renderer)
  File "/usr/lib/python3.4/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/axis.py", line 1119, in draw
    tick.draw(renderer)
  File "/usr/lib/python3.4/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/axis.py", line 249, in draw
    self.label1.draw(renderer)
  File "/usr/lib/python3.4/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/matplotlib/text.py", line 642, in draw
    ismath=ismath, mtext=mtext)
  File "/usr/lib/python3.4/site-packages/matplotlib/backends/backend_cairo.py", line 194, in draw_text
    self._draw_mathtext(gc, x, y, s, prop, angle)
  File "/usr/lib/python3.4/site-packages/matplotlib/backends/backend_cairo.py", line 247, in _draw_mathtext
    ctx.show_text(s)
TypeError: Can't convert 'bytes' object to str implicitly
@tacaswell
Copy link
Member

Which version of mpl and can you check if this still exists on master?

Yay python3 strings!

@tacaswell tacaswell added this to the next point release milestone Jun 11, 2015
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jun 11, 2015
@count0
Copy link
Author

count0 commented Jun 11, 2015

That is version 1.4.3.

I can't check on master right now. But I can say that I have been experiencing this bug for a very long time. I usually just modify the line in question locally, and keep going. Since the bug never went away, I decided to report it (should have done it a long time ago).

@tacaswell
Copy link
Member

Wait, this depends on using log scale being on?!

I can not reproduce this, but the gui window is way broken (it is just blank for me).

@count0
Copy link
Author

count0 commented Jul 7, 2015

Yes, the bug happens specifically for log scale!

Do you really get no errors with the above example as it is (no GUI)?

@jenshnielsen
Copy link
Member

I can reproduce this using 1.4.3 but only when using py3cairo. With cairocffi everything seems to be fine. Furthermore I cannot reproduce the errors with master using either cairocffi or py3cairo

Matplotlib prefers cairocffi over py3cairo since it fixes various issues. @count0 can you try with cairocffi
Depending on your platform you should be able to install cairocffi with pip?

pip3 install cairocffi

@count0
Copy link
Author

count0 commented Jul 7, 2015

@jenshnielsen I can confirm that I do not observe this problem with cairocffi.

@jenshnielsen
Copy link
Member

Thanks I am going to close the issue then on the basis of it being fixed on master with py3cairo and working with cairocffi

If you can reproduce the issue with py3cairo on master please ping to have the issue reopened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

No branches or pull requests

3 participants