How to get started/use matplotlib in kivy

后端 未结 1 1172
别那么骄傲
别那么骄傲 2020-12-10 13:56

I have recently learned a bit of matplotlib and would like to use it within kivy. I have read a little documentation on the garden here and there but don\'t really understan

相关标签:
1条回答
  • 2020-12-10 14:00

    Here is the simplest example possible for kivy-garden matplotlib and kivy. If you would like to do more advanced things, check out their examples: https://github.com/kivy-garden/garden.matplotlib/tree/master/examples I think it should be enough to get you started with your plot.

    Below I am adding it to a BoxLayout, you can add more widgets to this BoxLayout or add this BoxLayout somewhere else.

    python code example.py:

    from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
    from kivy.app import App
    from kivy.uix.boxlayout import BoxLayout
    import matplotlib.pyplot as plt
    
    plt.plot([1, 23, 2, 4])
    plt.ylabel('some numbers')
    
    class MyApp(App):
    
        def build(self):
            box = BoxLayout()
            box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
            return box
    
    MyApp().run()
    

    0 讨论(0)
提交回复
热议问题