kivy-garden / garden.matplotlib

Matplotlib backends using kivy
MIT License
104 stars 50 forks source link

Cannot import with matplotlib 3.0.0 installed #58

Open cYclonEK opened 6 years ago

cYclonEK commented 6 years ago

C:\Users\enzok\AppData\Local\Programs\Python\Python36\python.exe D:/py_projs/every_day_task/test2.py [INFO ] [Logger ] Record log in C:\Users\enzok.kivy\logs\kivy_18-09-20_37.txt [INFO ] [Kivy ] v1.10.1 [INFO ] [Python ] v3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] Traceback (most recent call last): File "D:/py_projs/every_day_task/test2.py", line 1, in from kivy.garden.matplotlib import * File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\garden__init.py", line 100, in load_module return self._load_module(fullname, moddir) File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\garden__init__.py", line 104, in _load_module ('', '', imp.PKG_DIRECTORY)) File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\imp.py", line 244, in load_module return load_package(name, filename) File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\imp.py", line 216, in load_package return _load(spec) File "C:\Users\enzok.kivy\garden\garden.matplotlib\init__.py", line 1, in from kivy.garden.matplotlib.backend_kivy import FigureCanvasKivy,\ File "C:\Users\enzok.kivy\garden\garden.matplotlib\backend_kivy.py", line 257, in from matplotlib.font_manager import weight_as_number ImportError: cannot import name 'weight_as_number'

mcu101 commented 6 years ago

Hi, weight_as_number() was deprecated in matplotlib 2.1. I'm trying to develop a workaround by substituting the call to weight_as_number() in backend_kivy.py line 669 with an equivalent method that could be implemented completely within backend_kivy.py. This was weight_as_number()'s implementation:

def weight_as_number(weight): """ Return the weight property as a numeric value. String values are converted to their corresponding numeric value. """ if isinstance(weight, six.string_types): try: weight = weight_dict[weight.lower()] except KeyError: weight = 400 elif weight in range(100, 1000, 100): pass else: raise ValueError('weight not a valid integer') return weight

https://github.com/matplotlib/matplotlib/blob/0b604b3a57a62e70620aaf66756bb9233713a5a4/lib/matplotlib/font_manager.py

mcu101 commented 6 years ago

Ok, so I implemented weight_as_number() within backend_kivy.py but it seems like that not the only incompatibility with matplotlib 3.0.0. Running test_plt.py now gives the following error regarding matplotlib's backend_bases.py script:

`Traceback (most recent call last): File "C:/Users/CarlosM/PycharmProjects/kivyplt/venv/test_plt.py", line 100, in plt.show() File "C:\Users\CarlosM\PycharmProjects\kivyplt\venv\lib\site-packages\matplotlib\pyplot.py", line 253, in show return _show(*args, **kw) File "C:\Users\CarlosM\PycharmProjects\kivyplt\venv\lib\site-packages\matplotlib\backend_bases.py", line 3300, in call return self.show(block=block) File "C:\Users\CarlosM\PycharmProjects\kivyplt\venv\lib\site-packages\matplotlib\backend_bases.py", line 3266, in show cls.mainloop() TypeError: mainloop() missing 1 required positional argument: 'self'

Process finished with exit code 1`

Out of curiosity, I changed matplotlib's backend_bases.py implementation to call cls.mainloop(self) with the self argument as suggested by the TypeError. But this time I got the error: NameError: name 'self' is not defined.

Any suggestions? Does anybody know more or less how much effort is needed to get the matplotlib Kivy flower to work with matplotlib 3.0.0? Would it be trivial?

mcu101 commented 6 years ago

By the way, it's still possible to get it to run on a virtual environment by installing matplotlib 2.0.0:

python -m pip install -U --force-reinstall matplotlib==2.0.0

cYclonEK commented 6 years ago

Hello @mcu101 Thank you so much for your effort I am just a beginner on these kivy and matplotlib things Sorry that I cannot provide you more Wish you good luck on this issue

matham commented 6 years ago

Did https://github.com/kivy-garden/garden.matplotlib/pull/62 fix your issue?

mcu101 commented 6 years ago

@matham: I'll check it out in the next few days.

tacaswell commented 5 years ago

@mcu101 pip install 'matplotlib<3.0' is probably better so you will get the latest version of 2.2.

Did it ever get sorted out if this backend works with mpl >= 3.0?

RobertFlatt commented 4 years ago

Try this:

from matplotlib import _png

from matplotlib import _path

Starosielec commented 2 years ago

instead of altering kivy.garden code, this one works for me

import matplotlib
matplotlib._png = None
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg