Advertisement
Gronario

Untitled

Apr 5th, 2021
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. #-----------main.py
  2.  
  3.  
  4. from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
  5. from kivy.app import App
  6. from kivy.uix.boxlayout import BoxLayout
  7. import matplotlib.pyplot as plt
  8. import numpy as np
  9.  
  10. from kivy_garden.graph import Graph, MeshLinePlot
  11. from kivy.uix.tabbedpanel import TabbedPanel
  12. from kivy.lang import Builder
  13. from kivy.uix.relativelayout import RelativeLayout
  14. from kivy.uix.floatlayout import FloatLayout
  15. from kivy.properties import ObjectProperty
  16.  
  17.  
  18.  
  19. Builder.load_file('tab.kv')
  20.  
  21.  
  22. class Plot(TabbedPanel):
  23.     name = ObjectProperty(None)
  24.  
  25.     def btn(self):
  26.         x=np.arange(-4,4,0.1)
  27.         y=np.log(x)
  28.         plt.plot(x,y,"g",label="first line")
  29.         plt.legend()
  30.         plt.xlabel("x")
  31.         plt.ylabel("y")
  32.         plt.title("first graphic",fontsize=15)
  33.         plt.grid(True)
  34.         box = BoxLayout()
  35.         box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
  36.  
  37.  
  38. class MyApp(App):
  39.  
  40.     def build(self):
  41.  
  42.         return Plot()
  43.  
  44. if __name__ == '__main__':
  45.     MyApp().run()
  46. #------------------- tab.kv
  47.  
  48. <Plot>:
  49.  
  50.     name:name
  51.  
  52.     size_hint: 1,1
  53.     pos_hint: {'center_x': .5, 'center_y': .5}
  54.  
  55.     do_default_tab: False
  56.  
  57.  
  58.     TabbedPanelItem:
  59.         text: 'first tab'
  60.  
  61.         FloatLayout:
  62.  
  63.             Label:
  64.  
  65.                 font_size:30
  66.                 halign: 'center'
  67.                 text: 'test\ntest1\ntest2'
  68.                 size_hint: 0.3,0.1
  69.                 pos_hint: {"x":0.5-0.3/2,"top":0.5+0.1/2}
  70.  
  71.  
  72.     TabbedPanelItem:
  73.         text: 'second tab'
  74.  
  75.         FloatLayout:
  76.  
  77.             Button:
  78.                 id: name
  79.                 text:"line chart"
  80.                 size_hint: 0.3,0.1
  81.                 pos_hint: {"x":0.02,"top":0.98}
  82.                 on_press:root.btn()
  83.  
  84.  
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement