python-3.xmacoskivykivy-languagematplotlib-widget

Kivy Matplotlib cannot be founded


I'm using kivy and matplotlib for visualization of data, these are the libraries:

`from kivy.uix.button import Button
from kivy.uix.spinner import Spinner

import pandas as pd
import matplotlib.pyplot as plt
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg as FCK`

`def view_stats(self):
    plt.cla()
    self.ids.analysis_res.clear_widgets()
    target_product = self.ids.target_product.text
    target = target_product[:target_product.find(' | ')]
    name = target_product[target_product.find(' | '):]

    df = pd.read_csv('products_purchase.csv')
    purchases = []
    dates = []
    count = 0
    for x in range(len(df)):
        if str(df.Product_Code[x]) == target:
            purchases.append(df.Purchased[x])
            dates.append(count)
            count += 1
    plt.bar(dates, purchases, color='teal', label=name)
    plt.ylabel('Total Purchases')
    plt.xlabel('day')

    self.ids.analysis_res.add_widget(FCK(plt.gcf()))`

When I run my code, it goes fine except for this function. I's not working because of the last import.

I have already downloaded kivy, kivy-garden and matplotlib as well. However, when I import:

from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg

I cannot run my program. Because of this only line


`

`from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg as FCK
   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
   File "<frozen importlib._bootstrap>", line 640, in _load_backward_compatible
 KeyError: 'kivy.garden.matplotlib'
`

Is there any suggestions? any other package that might be easier to use?


Solution

  • I founded the solution installing using garden

    > pip install kivy_garden
    > garden install matplotlib