問題描述
我最近學習了一點 matplotlib,并想在 kivy 中使用它.我在這里和那里閱讀了一些關于花園的文件,但并不真正理解它.我已經安裝了 kivy garden 和 matplotlib 但不知道如何從這里開始.我只是想將一個已經完成的 matplotlib 圖添加到 kivy 中.我將不勝感激逐步簡化的說明,說明如何將我已經編碼到 kivy 中的內容并顯示出來.謝謝
這是 kivy-garden matplotlib 和 kivy 的最簡單示例.如果您想做更高級的事情,請查看他們的示例:
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 understand it. I have installed kivy garden and matplotlib but don't know how to proceed from here. I simply want to add a already completed matplotlib graph into kivy. I would appreciate a step by step simplified set of instructions of how to get what I already coded into kivy and get it to display. Thanks
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()
這篇關于如何在 kivy 中開始/使用 matplotlib的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!