#!/usr/bin/env pythonfrom matplotlib.backends.backend_tkagg import FigureCanvasTkAggimport PySimpleGUI as sgimport matplotlibimport pylabmatplotlib.use('TkAgg')"""Demonstrates one way of embedding PyLab figures into a PySimpleGUI window."""# ------------------------------- PASTE YOUR PYLAB CODE HERE -------------------------------from numpy import sinfrom numpy import cosx = pylab.linspace(-3, 3, 30)y = x**2pylab.plot(x, sin(x))pylab.plot(x, cos(x), 'r-')pylab.plot(x, -sin(x), 'g--')fig = pylab.gcf()figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds# ------------------------------- END OF YOUR MATPLOTLIB CODE -------------------------------# ------------------------------- Beginning of Matplotlib helper code -----------------------def draw_figure(canvas, figure, loc=(0, 0)):figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)figure_canvas_agg.draw()figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)return figure_canvas_agg# ------------------------------- Beginning of GUI CODE -------------------------------# define the window layoutlayout = [[sg.Text('Plot test', font='Any 18')],[sg.Canvas(size=(figure_w, figure_h), key='canvas')],[sg.OK(pad=((figure_w / 2, 0), 3), size=(4, 2))]]# create the form and show it without the plotwindow = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI',layout, finalize=True)# add the plot to the windowfig_canvas_agg = draw_figure(window['canvas'].TKCanvas, fig)event, values = window.read()window.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。