本文整理汇总了Python中matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.create_image方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasTkAgg.create_image方法的具体用法?Python FigureCanvasTkAgg.create_image怎么用?Python FigureCanvasTkAgg.create_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_tkagg.FigureCanvasTkAgg
的用法示例。
在下文中一共展示了FigureCanvasTkAgg.create_image方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import create_image [as 别名]
#.........这里部分代码省略.........
self.rescaler = util.arcsinhStretch
self.scaleImage()
self.drawImage()
# Bind the sliders to the scaleImage() method
self.scaleValue.bind("<ButtonRelease-1>", self.redraw)
self.minValue.bind("<ButtonRelease-1>", self.redraw)
self.maxValue.bind("<ButtonRelease-1>", self.redraw)
self.scalingOption.bind("<ButtonRelease-1>", self.redraw)
def setRescaler(self, event):
self.rescaler = scalingTypes[self.scalingName.get()]
def redraw(self, event=None):
""" This rescales and redraws the image using the current values for scaling """
self.scaleImage()
self.drawImage()
def updateThumbnail(self, event):
""" """
self.lastMousePosition = (event.x, event.y)
self.pilThumbnail = self.pilImage.transform(self.pilImage.size, Image.EXTENT, (event.x-25,event.y-25,event.x+25,event.y+25))
self.thumbnailImage = ImageTk.PhotoImage(self.pilThumbnail.resize((200,200)))
self.thumbnailImageLabel.configure(image=self.thumbnailImage)
def scaleImage(self):
""" This method re-scales the image data """
self.scaledData = 255.0*self.rescaler(self.rawData, beta=10.**self.scaleValue.get(), min=self.minValue.get(), max=self.maxValue.get(), clip=True)
def plotContour(self, event):
""" If the 'c' key is pressed, generate a contour plot of whatever is in the thumbnail zoom box """
self.contourPlot = Tk.Toplevel(self.master)
self.contourPlot.title("Contour plot for: {0}".format(self.filename))
rawShape = self.rawData.shape
lastx, lasty = self.lastMousePosition
lastx = round(lastx/self.zoomFactor)
lasty = round(lasty/self.zoomFactor)
boxHalfSize = 25/self.zoomFactor
x1,y1,x2,y2 = [x for x in map(round, (lastx-boxHalfSize,lasty-boxHalfSize,lastx+boxHalfSize,lasty+boxHalfSize))]
if x1 < 0:
x1 = 0
x2 = boxHalfSize*2
if x2 > rawShape[1]:
x2 = rawShape[1]
x1 = x2 - boxHalfSize*2
if y1 < 0:
y1 = 0
y2 = boxHalfSize*2
if y2 > rawShape[0]:
y2 = rawShape[0]
y1 = y2 - boxHalfSize*2
thumbData = self.rawData[y1:y2, x1:x2]
shp = thumbData.shape
x,y = np.meshgrid(range(shp[0]), range(shp[1]))
self.fig = Figure(figsize=(5,5))
ax = self.fig.add_subplot(111)
ax.contour(x, y, thumbData)
ax.set_ylim(ax.get_ylim()[::-1])
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
self.canvas = FigureCanvasTkAgg(self.fig, master=self.contourPlot)
self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
def drawImage(self):
""" This method will draw the image into a PhotoImage object in the new image window """
self.pilImage = Image.fromarray(self.scaledData.astype(np.uint8))
newSize = (int(self.pilImage.size[0]*self.zoomFactor), int(self.pilImage.size[1]*self.zoomFactor))
self.pilImage = self.pilImage.resize(newSize)
self.tkImage = ImageTk.PhotoImage(self.pilImage)
self.canvas = Tk.Canvas(self.ImageWindow, width=newSize[0], height=newSize[1], bd=0)
self.canvas.create_image(0, 0, image=self.tkImage, anchor="nw")
self.canvas.grid(row=0, column=2, rowspan=5, sticky="nswe")
self.canvas.bind("<Motion>", self.updateThumbnail)
self.canvas.bind("c", self.plotContour)
self.canvas.focus_set()
""" # Code for source detection:
numSigma = 2.
labels, num = snd.label(self.rawData > (numSigma*np.std(self.rawData)), np.ones((3,3)))
coords = snd.center_of_mass(self.rawData, labels, range(1,num+1))
rad = 5.
for coord in coords:
y,x = coord
x = x*self.zoomFactor
y = y*self.zoomFactor
circ1 = self.canvas.create_oval(x-rad,y-rad,x+rad,y+rad, outline='red')
"""
self.pilThumbnail = self.pilImage.transform(self.pilImage.size, Image.EXTENT, (0,0,50,50))
self.pilThumbnail = self.pilThumbnail.resize((200,200))
self.thumbnailImage = ImageTk.PhotoImage(self.pilThumbnail)
self.thumbnailImageLabel = Tk.Label(self.ImageWindow, image=self.thumbnailImage, command=None)
self.thumbnailImageLabel.grid(row=4, column=0, columnspan=2, rowspan=5)