【发布时间】:2013-09-04 00:12:22
【问题描述】:
我正在尝试执行以下操作:
- 使用 matplotlib 包创建带有
imshow()的绘图,它提供matplotlib.image.AxesImage - 将
matplotlib.image.AxesImage转换为PIL.ImageTk.PhotoImage - 将此
PIL.ImageTk.PhotoImage用作 TkInter 画布上的图像
如何在不保存任何图像的情况下完成上述操作?
在参考了一篇帖子后,我尝试使用以下代码直接对我的数据进行颜色编码:
from Tkinter import *
from PIL import ImageTk,Image
import numpy as np
from pylab import cm
root=Tk()
canvas = Canvas(root)
canvas.pack(expand = YES, fill = BOTH)
x = np.linspace(0, 2 * np.pi, 120)
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
myarray = np.sin(x) + np.cos(y)
image1 = Image.fromarray(np.uint8(cm.gist_earth(myarray)*255))
test = canvas.create_image(10,10,image = image1)
#canvas.itemconfig(test, image=nextimage)
mainloop()
上面的代码给出了错误
TclError: image "<PIL.Image.Image image mode=RGBA size=120x100 at 0x2DC01E8>" doesn't exist
可能是什么问题?
【问题讨论】:
标签: python matplotlib tkinter python-imaging-library