()
| 17 | return figure_canvas_agg |
| 18 | |
| 19 | def main(): |
| 20 | # define the form layout |
| 21 | layout = [[sg.Text('Animated Matplotlib', size=(40, 1), justification='center', font='Helvetica 20')], |
| 22 | [sg.Canvas(size=(640, 480), key='-CANVAS-')], |
| 23 | [sg.Button('Exit', size=(10, 2), pad=((280, 0), 3), font='Helvetica 14')]] |
| 24 | |
| 25 | # create the form and show it without the plot |
| 26 | window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI', layout, finalize=True) |
| 27 | |
| 28 | canvas_elem = window['-CANVAS-'] |
| 29 | canvas = canvas_elem.TKCanvas |
| 30 | # draw the intitial scatter plot |
| 31 | fig, ax = plt.subplots() |
| 32 | ax.grid(True) |
| 33 | fig_agg = draw_figure(canvas, fig) |
| 34 | |
| 35 | while True: |
| 36 | event, values = window.read(timeout=10) |
| 37 | if event in ('Exit', None): |
| 38 | exit(69) |
| 39 | |
| 40 | ax.cla() |
| 41 | ax.grid(True) |
| 42 | for color in ['red', 'green', 'blue']: |
| 43 | n = 750 |
| 44 | x, y = rand(2, n) |
| 45 | scale = 200.0 * rand(n) |
| 46 | ax.scatter(x, y, c=color, s=scale, label=color, alpha=0.3, edgecolors='none') |
| 47 | ax.legend() |
| 48 | fig_agg.draw() |
| 49 | window.close() |
| 50 | |
| 51 | |
| 52 | if __name__ == '__main__': |
no test coverage detected