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

Gtk3Agg backend (Ubuntu 14.04) #2976

Closed
tobias47n9e opened this issue Apr 12, 2014 · 23 comments
Closed

Gtk3Agg backend (Ubuntu 14.04) #2976

tobias47n9e opened this issue Apr 12, 2014 · 23 comments

Comments

@tobias47n9e
Copy link
Contributor

When running the example from the Matplotlib website:

http://matplotlib.org/examples/user_interfaces/embedding_in_gtk3.html

on Ubuntu 14.04 (64 bit), I get the following error:

/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py:12: UserWarning: The Gtk3Agg backend is not known to work on Python 3.x.
  warnings.warn("The Gtk3Agg backend is not known to work on Python 3.x.")
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
@tacaswell
Copy link
Member

@farzia Can you take a look at this?

@tobias47n9e
Copy link
Contributor Author

This might be a somewhat related issue:

https://bugzilla.redhat.com/show_bug.cgi?id=1049624

I tried out a few different backends, but that just produced similar errors.

@tacaswell
Copy link
Member

The redhat issue is an issue with setting the default backend to one that is not installed (which looking at how we do thin is setup.py should probably be rationalized as currently it looks like it goes with the last checked installed backend).

I can not reproduce this with 1.3.1, but on 13.10

@jenshnielsen
Copy link
Member

I think this is a know issue the release version of pycairo does not implement this function. AFAIK this is one of the reasons that the master branch now supports cairocffi as an alternative to pycairo. I think that @mdboom might know more.

@timovwb
Copy link
Contributor

timovwb commented Apr 15, 2014

@jenshnielsen is right. To use the GTK3 backend with Python 3 you have to use cairocffi instead of pycairo. Luckily it's easy to install through pip:

sudo pip install cairocffi

@tobias47n9e
Copy link
Contributor Author

@timovwb Thanks for the answer. I had to use:

sudo pip3 install cairocffi

But the example still doesn't work:

/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py:12: UserWarning: The Gtk3Agg backend is not known to work on Python 3.x.
  warnings.warn("The Gtk3Agg backend is not known to work on Python 3.x.")
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 52, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.

@jenshnielsen
Copy link
Member

Are you using the master branch? As I wrote above only the master branch has support for cairocffi at the moment. It does not work in 1.3.1 or lower nor in the 1.3.x branch.

@tobias47n9e
Copy link
Contributor Author

Ok, now I understand. I am using:

python3-matplotlib 1.3.1-1ubuntu5

Going to try to add this repository: https://launchpad.net/~takluyver/+archive/matplotlib-daily

@timovwb
Copy link
Contributor

timovwb commented Apr 15, 2014

That looks like an outdated PPA, latest version there is 1.3.0. It's possible to install matplotlib git master through pip, maybe someone else can help you with the correct command.

@takluyver
Copy link
Contributor

It's not really 1.3.0, I just haven't bumped the version number in a while. However, it's not building at present because of #2916

@mdboom
Copy link
Member

mdboom commented Apr 17, 2014

This is a known issue on all released versions of matplotlib, and is explicit in the error message:

UserWarning: The Gtk3Agg backend is not known to work on Python 3.x.
  warnings.warn("The Gtk3Agg backend is not known to work on Python 3.x.")

matplotlib master has a fix to make this compatible with cairocffi, but with pycairo it still doesn't work (and may never, as pycairo appears to be abandoned). See #1227.

Closing as already fixed.

@mdboom mdboom closed this as completed Apr 17, 2014
@ghost
Copy link

ghost commented Apr 1, 2015

So I guys I managed to get the plots working in Python 3.x by using:

from cairocffi import *

but is there a better way of doing this without importing the entire namespace?

@jenshnielsen
Copy link
Member

Which version of Matplotlib is this. All recent versions (al least 1.4.x) should support cairocffi out of the box without the need to do any special imports.

@ghost
Copy link

ghost commented Apr 1, 2015

version 1.4.3 

@jenshnielsen
Copy link
Member

Can you explain in some more detail what you are trying to do and any error messages you get?

As stated above plotting using the GTK3Agg backend should work without any need for work arounds
like the one you mention.

@ghost
Copy link

ghost commented Apr 1, 2015

Downloaded matplotlib and numpy via pip. Launched the script and triggered "Not Implemented backend" error, and also the warning message "Gt3Agg is known to not work in Python 3.x". Applied timowcb's fix: sudo pip3 install cairocffi and importing it in the code got my problem fixed.

After reading what you mentioned about the master branch being updated to fix this issue, I'm thinking it perhaps has to do with pip installing an older version from the package index, instead of the updated branch? Have no idea, anways got my problem solved so all is well I guess.

@snowman907
Copy link

I am using Matplotlib 1.5 and the problem still exist. Is Zenith-matic's approach using- "from cairocffi import * " the only approach, I thought Python 3.x is a stable platform and worth the upgrade?!

import matplotlib
matplotlib.version
'1.5.0'
import matplotlib.pyplot as plt;import numpy as np;x=np.arange(1,10,1);plt.plot(x); plt.show()

Warning (from warnings module):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 18
"The Gtk3Agg backend is known to not work on Python 3.x with pycairo. "
UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo. Try installing cairocffi.
[<matplotlib.lines.Line2D object at 0x7f343815d898>]
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.

@jenshnielsen
Copy link
Member

@snowman907 There exists 3 different Cairo wrappers for python. The 2 official ones py2cairo (python 2 only) and py3cairo (python 3) only. Unfortunately py3cairo does not implement Surface.create_for_data which we need for the GTK3Agg backend. However a third exists which is cairocffi which does support
Surface.create_for_data normally Matplotlib should prefer cairocffi over py3cairo but it seems that does not work for you and Zenith-matic without first importing cairocffi.

For me the following works with cairocffi installed and fails when I uninstall it.

import matplotlib
matplotlib.use('Gtk3Agg')
import matplotlib.pyplot as plt
plt.plot(range(100))
plt.show()

Could you try running the following with python3.5 and paste the output?

try:
    import cairocffi as cairo
except ImportError:
    try:
        import cairo
    except ImportError:
        raise ImportError("Cairo backend requires that cairocffi or pycairo is installed.")
    else:
        HAS_CAIRO_CFFI = False
else:
    HAS_CAIRO_CFFI = True
print(HAS_CAIRO_CFFI)

@snowman907
Copy link

Trying:
import matplotlib
matplotlib.use('Gtk3Agg')
import matplotlib.pyplot as plt
plt.plot(range(100))
plt.show()

returned :
Warning (from warnings module):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 18
"The Gtk3Agg backend is known to not work on Python 3.x with pycairo. "
UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo. Try installing cairocffi.
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.

@jenshnielsen
Copy link
Member

My first suggestion was NOT a suggestion it was an example of a pice of code that works with Cairocffi and not with py3cairo Given that you can't install cairocffi it is completely expected that the example doesn't work.

Which system are you using? On Ubuntu you should be able to install cairocffi with:

sudo apt-get install python3-cairocffi

@snowman907
Copy link

I did not understand from your example
import matplotlib
matplotlib.use('Gtk3Agg')
import matplotlib.pyplot as plt
plt.plot(range(100))
plt.show()

that is uses Cairocffi.

sudo apt-get install python3-cairocffi

Installed well and the above example worked well.

The first example plotted well. The second example got TRUE.

I am a bit surprise this problem is not more common/ better document on the web.

Thanks for the fast response.

On Thu, Nov 12, 2015 at 10:42 PM, Jens Hedegaard Nielsen <
notifications@github.com> wrote:

My first suggestion was NOT a suggestion it was an example of a pice of
code that works with Cairocffi and not with py3cairo Given that you can't
install cairocffi it is completely expected that the example doesn't work.

Which system are you using? On Ubuntu you should be able to install
cairocffi with:

sudo apt-get install python3-cairocffi


Reply to this email directly or view it on GitHub
#2976 (comment)
.

Eyal Saiet

Project manager
Remote sensing and in-situ measurements

Geophysical Institute
University of Alaska Fairbanks
Fairbanks, AK 99775
(907) 750 6555 (cell)

ejsaiet@alaska.edu

@jenshnielsen
Copy link
Member

The example

import matplotlib
matplotlib.use('Gtk3Agg')
import matplotlib.pyplot as plt
plt.plot(range(100))
plt.show()

uses cairocffi if that is installed. If not it will use py2cairo on python2 and py3cairo on python3. Unfortunalty py3cairo does not currently work for the gtk3agg backend (it does work for the gtk3cairo backend) There might be a new release of py3cairo sometime in the future fixing this but my hopes are not high. We reported the issue to the py3cairo developers several years ago.

@danijar
Copy link

danijar commented Dec 10, 2015

Thanks, hope that will get a fix.

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

No branches or pull requests

8 participants