我试图找到一个解决方案,将图形嵌入到kivy小部件中。似乎只有一个使用kivy园景图(sin wave)的例子,我在我的应用程序中实现这个有困难。
以下是我与
合作的代码#!/usr/bin/kivy
import kivy
from random import random
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.switch import Switch
from kivy.uix.label import Label
from kivy.garden.graph import Graph, MeshLinePlot
from math import sin
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from kivy.graphics import *
from kivy.config import Config
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '480')
Builder.load_string("""
<Menuscreen>:
#Handling the gesture event.
ScreenManager:
id: manager
Screen:
id: main_screen
name:'main_screen'
FloatLayout:
MyGraph:
size_hint: None, None
size: 800,600
pos: 25,25
""")
class MyGraph(Graph):
def __init__(self, **kwargs):
super(MyGraph, self).__init__(**kwargs)
self.xlabel = 'This is the X axis'
self.ylabel = 'This is the Y axis'
self.x_ticks_minor = 5
self.x_ticks_major = 25
self.y_ticks_major = 1
self.y_grid_label = True
self.x_grid_label = True
self.x_grid = True
self.y_grid = True
self.xmax = 100
self.xmin = -0
self.ymin = -1
self.ymax = 1
self.plot = MeshLinePlot(color=[1, 0, 0, 1])
self.plot.points = [(x, sin(x / 10.)) for x in range(0, 100)]
self.add_plot(self.plot)
class MenuScreen(Screen):
pass
sm = ScreenManager()
menu_screen = MenuScreen(name='menu')
sm.add_widget(menu_screen)
class TestApp(App):
def build(self):
return sm
if __name__ == '__main__':
TestApp().run()
似乎出现了所有轴标签,但图中的点未出现。是否有一些我不想让它出现?提前感谢您的建议。
答案 0 :(得分:0)
Github的Mostafar问了同样的问题,感谢@Tshirtman,提供了以下答案:
mostafar于2014年4月27日评论在与@tshirtman聊天后,他发现问题出在stencilbuffer上,并将图形模块的init.py的第139行更改为:
self._fbo = Fbo(size = self.size,with_stencilbuffer = False)
在我的示例中可以看到它,但是图形的新功能(SmoothLinePlot)会出现很多问题。