python图形事例_Python图形之-tkinter与matplotlib结合案例

使用matplotlib绘制图像,并显示到thinter已有的画布中,如何进行两个包的连接,具体案例如下:

1 import matplotlib 2 matplotlib.use('TkAgg') 3 from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 4 from matplotlib.figure import Figure 5 from tkinter import * 6 root = Tk() 7 root.title("tkinter and matplotlib") 8 f = Figure(figsize=(2.52, 2.56), dpi=100)#figsize定义图像大小,dpi定义像素 9 f_plot = f.add_subplot(111)#定义画布中的位置 10 def other_picture_alg(): #数据相关的算法应该与plot分离开 11 x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 12 y = [3, 6, 9, 12, 15, 18, 15, 12, 15, 18] 13 return x, y 14 def draw_picture(): 15 f_plot.clear() 16 x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] #关于数据的部分可以提取出来 17 y = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30] 18 f_plot.plot(x, y) 19 canvs.draw() 20 def draw_picture2(): 21 f_plot.clear() 22 x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] #关于数据的部分可以提取出来 23 y = [2, 4, 6, 8, 10, 8, 6, 4, 2, 0] 24 f_plot.plot(x

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值