I am trying to do the following:
- Create plot with
imshow()
using matplotlib package, which givesmatplotlib.image.AxesImage
- Convert
matplotlib.image.AxesImage
toPIL.ImageTk.PhotoImage
- Use this
PIL.ImageTk.PhotoImage
as image on TkInter canvas
How can I accomplish the above without saving any image?
After referring a post I tried to directly color code my data with the following code:
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()
The above code gives the error
TclError: image "<PIL.Image.Image image mode=RGBA size=120x100 at 0x2DC01E8>" doesn't exist
What might be the problem?