Select your language

To visualize plots, diagrams and other data in Kivy is it necessary to install an adittional module. The Kivy community provides the Kivy-Garden/Matplotlib for this purpose.

If you havent installed the Kivy Garden, run this command first

pip3 install kivy-garden

and after a restart you can get the matplotlib

garden install matplotlib

To check your installed modules can you use the command

garden list

that creates a simple list of all your garden modules.

Now that you have the matplotlib extension for Kivy do you need to install the original Matplotlib

python3 -m pip install -U matplotlib

The example below is a little program that will show a simple bar plot.

from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import matplotlib.pyplot as plt

#data = {'Monday': 10, 'Tuesday': 15, 'Wednesday': 5, 'Thursday': 20, 'Friday': 12}
values_xaxis = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
values_yaxis = [10, 15, 5, 25, 34, 55, 37]

fix, ax = plt.subplots()
ax.bar(values_xaxis, values_yaxis)
plt.ylabel('Visitors per Day')

class MyApp(App):

    def build(self):
        box = BoxLayout()
        box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
        return box

MyApp().run()

 Das Ergebnis ist ein einfacher Plot, der Besucherzahlen über den Wochentagen als Balkengrafik dasrstellt.