问题描述
我最近学到了一些matplotlib,想在kivy中使用它.我已经在这里和那里的花园里阅读了一些文档,但并不太了解.我已经安装了kivy garden和matplotlib,但是不知道如何从这里继续.我只是想将一个已经完成的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
推荐答案
这里是kivy-garden matplotlib和kivy的最简单示例.如果您想做更高级的事情,请查看他们的示例: https: //github.com/kivy-garden/garden.matplotlib/tree/master/examples 我认为这足以使您开始进行设计.
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/examplesI think it should be enough to get you started with your plot.
下面,我将其添加到BoxLayout中,您可以在此BoxLayout中添加更多小部件,也可以在其他位置添加此BoxLayout.
Below I am adding it to a BoxLayout, you can add more widgets to this BoxLayout or add this BoxLayout somewhere else.
python代码example.py:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!