Python tkinter 在背景图片上怎么加pylab画出的图

在tkinter上已经加入了背景图片,想在上面某个位置显示pylab画出的图,而且,没画出图时显示背景,画出图后,没有被挡住的背景部分还在
比如我想在框中加pylab画出的图,但是要求图画出来之前原背景不变

做了一个简单的,不过没有用pylab。

理解下来,只要有图像能保存下来,就应该没问题,

# coding: utf-8

import Tkinter as TK
from PIL import Image, ImageTk

def data_matplotlib():
    import numpy as np
    import matplotlib.pyplot as plt
    
    ....
    plt.savefig('tmp.png')
    return ImageTk.PhotoImage(Image.open('tmp.png'))

# Definition
image  = 'Hydrangeas.jpg'

# Tkinter
root = TK.Tk()
root.title('加载图形数据')
root.geometry('1024x768+1+1')
root.update()
canvas      = TK.Canvas(root, width=1024, height=768, bg='green')
image_data  = ImageTk.PhotoImage(Image.open(image))
canvas.create_image(0, 0, image=image_data, anchor=TK.NW)
i = data_matplotlib()
canvas.create_image(100, 200, image=i, anchor=TK.NW)
canvas.create_text(root.winfo_width()/2, root.winfo_height()/10,
    text='Sample', font=('Arial', 18), fill='white')
canvas.pack(side=TK.TOP, expand=1, fill='both')

root.mainloop()

不过,使用中间图片还是有点难看,不知道哪位对matplotlib熟悉点的可以指教一下?

温馨提示:答案为网友推荐,仅供参考