matplotlib in Kivy

1,037 views
Skip to first unread message

Michael Bertolli

unread,
Oct 8, 2015, 12:18:05 PM10/8/15
to kivy-...@googlegroups.com
Hi,

I'm attempting to use your matplotlib backend in Kivy, but running into trouble running the examples. I'm running with Kivy on OS X, and matplotlib 1.4.3. With each of the test_*.py example, I get the same error on lines of the form: 

figure, ax = plt.subplots()


For example, line 57 of test_plt.py. The error thrown is regarding the __init__(), and traces back to the event dispatcher:

 TypeError: __init__() takes exactly 2 arguments (1 given)


I've built basic functionality with Kivy (and am very comfortable with python in general), but debugging this is a level above my head. I'm sure it's a stupid setup problem on my end. 

Currently my work around is to use matplotlib to save *.png files and load them into the Kivy app, but I'm anxious to explore the backend you've developed!

Any help is appreciated to point me in the right direction,
Mik

David Aldrich

unread,
Oct 9, 2015, 5:52:49 AM10/9/15
to Kivy users support
Are you using Kivy 1.9.1-dev?  The matplotlib backend won't work with 1.9.0.

David

Leon A

unread,
Nov 24, 2015, 12:29:09 PM11/24/15
to Kivy users support
Im also getting the error below I am definitely using 1.9.1 on Ubuntu, any ideas?
 Traceback (most recent call last):
   
File "backend_kivyagg.py", line 96, in <module>
     
from kivy.garden.matplotlib.backend_kivy import FigureCanvasKivy,\
   
File "/usr/local/lib/python2.7/dist-packages/kivy/garden/__init__.py", line 100, in load_module
     
return self._load_module(fullname, moddir)
   
File "/usr/local/lib/python2.7/dist-packages/kivy/garden/__init__.py", line 104, in _load_module
     
('', '', imp.PKG_DIRECTORY))
   
File "/home/leon/.kivy/garden/garden.matplotlib/__init__.py", line 5, in <module>
     
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
   
File "/home/leon/.kivy/garden/garden.matplotlib/backend_kivyagg.py", line 100, in <module>
     register_backend
('png', 'backend_kivyagg', 'PNG File Format')
 
TypeError: register_backend() takes exactly 2 arguments (3 given)
leon@ubuntu
:~/.kivy/garden/garden.matplotlib$

Yoel Koenka

unread,
Mar 21, 2017, 6:15:35 PM3/21/17
to Kivy users support
I ran into the same problem. Working on Mac, using Kivy 1.9.1.
Did anyone get this solved?

Bill Janssen

unread,
May 4, 2017, 2:23:11 PM5/4/17
to Kivy users support
This works fine for me on all platforms, including Mac.  I'm using matplotlib 2.0 -- what version of matplotlib are you using?

Bill

Bill Janssen

unread,
May 4, 2017, 2:24:46 PM5/4/17
to Kivy users support

Yoel Koenka

unread,
May 4, 2017, 6:35:59 PM5/4/17
to kivy-...@googlegroups.com
Thanks Bill,
After finding this post, and looking at this example, I found a solution.
pyplt can be only imported after the matplotlib.use statement.
And in kivyagg is necessary for embedding the plot inside a kivy layout (I think)
import matplotlib
matplotlib.use("module://kivy.garden.matplotlib.backend_kivyagg")
from matplotlib import pyplot as plt
from kivy.garden.matplotlib import FigureCanvasKivyAgg

...
self.fig = plt.gcf()
self.add_widget(FigureCanvasKivyAgg(self.fig))

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/kE6QFoIV__w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bill Janssen

unread,
May 4, 2017, 9:19:31 PM5/4/17
to Kivy users support
Yes, that's a classic matplotlib gotcha.

Bill
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages