1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| from kivy.utils import platform
if platform != 'android': from kivy.config import Config
Config.set('input', 'mouse', 'mouse,disable_on_activity')
from kivy.lang import Builder from kivy.app import App import matplotlib.pyplot as plt import kivy_matplotlib_widget
KV = ''' Screen figure_wgt:figure_wgt BoxLayout: orientation:'vertical' BoxLayout: size_hint_y:0.2 Button: text:"home" on_release:app.home() ToggleButton: group:'touch_mode' state:'down' text:"pan" on_release: app.set_touch_mode('pan') self.state='down' ToggleButton: group:'touch_mode' text:"zoom box" on_release: app.set_touch_mode('zoombox') self.state='down' MatplotFigure: id:figure_wgt '''
class Test(App): lines = []
def build(self): self.screen = Builder.load_string(KV) return self.screen
def on_start(self, *args): fig, ax1 = plt.subplots(1, 1)
ax1.plot([0, 1, 2, 3, 4], [1, 2, 8, 9, 4], label='line1') ax1.plot([2, 8, 10, 15], [15, 0, 2, 4], label='line2')
self.screen.figure_wgt.figure = fig
def set_touch_mode(self, mode): self.screen.figure_wgt.touch_mode = mode
def home(self): self.screen.figure_wgt.home()
Test().run()
|