Ai
4 Star 4 Fork 0

Gitee 极速下载/pysimplegui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/PySimpleGUI/PySimpleGUI
克隆/下载
Demo_Matplotlib_PyLab.py 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
timkay@not.com 提交于 2024-02-12 23:14 +08:00 . First release of PySimpleGUI 5!
#!/usr/bin/env python
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import PySimpleGUI as sg
import matplotlib
import pylab
matplotlib.use('TkAgg')
"""
Demonstrates one way of embedding PyLab figures into a PySimpleGUI window.
Copyright 2023 PySimpleSoft, Inc. and/or its licensors. All rights reserved.
Redistribution, modification, or any other use of PySimpleGUI or any portion thereof is subject to the terms of the PySimpleGUI License Agreement available at https://eula.pysimplegui.com.
You may not redistribute, modify or otherwise use PySimpleGUI or its contents except pursuant to the PySimpleGUI License Agreement.
"""
# ------------------------------- PASTE YOUR PYLAB CODE HERE -------------------------------
from numpy import sin
from numpy import cos
x = pylab.linspace(-3, 3, 30)
y = x**2
pylab.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 layout
layout = [[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 plot
window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI',
layout, finalize=True)
# add the plot to the window
fig_canvas_agg = draw_figure(window['canvas'].TKCanvas, fig)
event, values = window.read()
window.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mirrors/pysimplegui.git
git@gitee.com:mirrors/pysimplegui.git
mirrors
pysimplegui
pysimplegui
master

搜索帮助