pythontkinter在一块区域中绘图_如何在Tkinter窗口中刷新matplotlib绘图?

# import modules that I'm using

import matplotlib

matplotlib.use('TKAgg')

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

from matplotlib.figure import Figure

import matplotlib.pyplot as pltlib

import Tkinter

from Tkinter import *

import numpy as np

import scipy as sc

#import matplotlib.pyplot as pltlib

# lmfit is imported becuase parameters are allowed to depend on each other along with bounds, etc.

from lmfit import minimize, Parameters, Minimizer

#Make object for application

class App_Window(Tkinter.Tk):

def __init__(self,parent):

Tkinter.Tk.__init__(self,parent)

self.parent = parent

self.initialize()

def initialize(self):

button = Tkinter.Button(self,text="Open File",command=self.OnButtonClick).pack(side=Tkinter.TOP)

self.canvasFig=pltlib.figure(1)

Fig = matplotlib.figure.Figure(figsize=(5,4),dpi=100)

FigSubPlot = Fig.add_subplot(111)

x=[]

y=[]

self.line1, = FigSubPlot.plot(x,y,'r-')

self.canvas = matplotlib.backends.backend_tkagg.FigureCanvasTkAgg(Fig, master=self)

self.canvas.show()

self.canvas.get_tk_widget().pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=1)

self.canvas._tkcanvas.pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=1)

self.resizable(True,False)

self.update()

def refreshFigure(self,x,y):

self.line1.set_xdata(x)

self.line1.set_ydata(y)

self.canvas.draw()

def OnButtonClick(self):

# file is opened here and some data is taken

# I've just set some arrays here so it will compile alone

x=[]

y=[]

for num in range(0,1000):x.append(num*.001+1)

# just some random function is given here, the real data is a UV-Vis spectrum

for num2 in range(0,1000):y.append(sc.math.sin(num2*.06)+sc.math.e**(num2*.001))

X = np.array(x)

Y = np.array(y)

self.refreshFigure(X,Y)

if __name__ == "__main__":

MainWindow = App_Window(None)

MainWindow.mainloop()

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值