Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-----------main.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
- import numpy as np
- from kivy_garden.graph import Graph, MeshLinePlot
- from kivy.uix.tabbedpanel import TabbedPanel
- from kivy.lang import Builder
- from kivy.uix.relativelayout import RelativeLayout
- from kivy.uix.floatlayout import FloatLayout
- from kivy.properties import ObjectProperty
- Builder.load_file('tab.kv')
- class Plot(TabbedPanel):
- name = ObjectProperty(None)
- def btn(self):
- x=np.arange(-4,4,0.1)
- y=np.log(x)
- plt.plot(x,y,"g",label="first line")
- plt.legend()
- plt.xlabel("x")
- plt.ylabel("y")
- plt.title("first graphic",fontsize=15)
- plt.grid(True)
- box = BoxLayout()
- box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
- class MyApp(App):
- def build(self):
- return Plot()
- if __name__ == '__main__':
- MyApp().run()
- #------------------- tab.kv
- <Plot>:
- name:name
- size_hint: 1,1
- pos_hint: {'center_x': .5, 'center_y': .5}
- do_default_tab: False
- TabbedPanelItem:
- text: 'first tab'
- FloatLayout:
- Label:
- font_size:30
- halign: 'center'
- text: 'test\ntest1\ntest2'
- size_hint: 0.3,0.1
- pos_hint: {"x":0.5-0.3/2,"top":0.5+0.1/2}
- TabbedPanelItem:
- text: 'second tab'
- FloatLayout:
- Button:
- id: name
- text:"line chart"
- size_hint: 0.3,0.1
- pos_hint: {"x":0.02,"top":0.98}
- on_press:root.btn()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement