本文整理汇总了Python中matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.grid方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasTkAgg.grid方法的具体用法?Python FigureCanvasTkAgg.grid怎么用?Python FigureCanvasTkAgg.grid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_tkagg.FigureCanvasTkAgg
的用法示例。
在下文中一共展示了FigureCanvasTkAgg.grid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import grid [as 别名]
class ImageSession:
def __init__(self, master, filename, hdu=0):
# filename should be a string!
self.filename = filename
self.hdu = hdu
# The master window?
self.master = master
if not os.path.exists(self.filename):
tkMessageBox.showerror("File not found", "File {0} doesn't exist!".format(file))
return
self.openFile()
self.createWindow()
def openFile(self):
# Try to open the file and read in the data from HDU
try:
hdulist = pf.open(self.filename)
try:
if hdulist[self.hdu].header['XTENSION'] == 'BINTABLE':
tkMessageBox.showerror("HDU Error", "The HDU {0} is not an ImageHDU!".format(self.hdu))
raise util.NotAnImageHDUError("The HDU {0} is not an ImageHDU!".format(self.hdu))
# HDU is a table -- throw an error!
except KeyError:
# HDU is an image, carry on!
pass
self.rawData = hdulist[self.hdu].data
self.rawData.shape
except IOError:
tkMessageBox.showerror("FITS file error ", "File {0} does not appear to be a valid FITS file!".format(self.filename))
raise util.ImageSessionError("File {0} does not appear to be a valid FITS file!".format(self.filename))
except AttributeError:
tkMessageBox.showerror("FITS file error ", "File {0} does not appear to have data in HDU 0.".format(self.filename))
raise util.ImageSessionError("File {0} does not appear to have data in HDU 0.".format(self.filename))
def createWindow(self):
# Create the actual window to draw the image and scale controls
self.ImageWindow = Tk.Toplevel(self.master)
self.ImageWindow.title(self.filename)
#self.ImageWindow.protocol("WM_DELETE_WINDOW", self.closeImage)
# TODO: THIS SHOULD DETECT SCREEN RESOLUTION
screenSize = (1050/1.5, 1680/1.5)
if self.rawData.shape[0] > screenSize[0] and self.rawData.shape[1] > screenSize[1]:
factor1 = screenSize[0] / self.rawData.shape[0]
factor2 = screenSize[1] / self.rawData.shape[1]
self.zoomFactor = min([factor1, factor2])
elif self.rawData.shape[1] > screenSize[0]:
self.zoomFactor = screenSize[0]/ self.rawData.shape[1]
elif self.rawData.shape[0] > screenSize[1]:
self.zoomFactor = screenSize[1] / self.rawData.shape[0]
else:
self.zoomFactor = 1.
# Create the image tools
scaleTypeLabel = Tk.Label(self.ImageWindow, text="Scaling: ")
scaleTypeLabel.grid(row=0, column=0)
self.scalingName = Tk.StringVar()
self.scalingName.set("arcsinh")
self.scalingOption = Tk.OptionMenu(self.ImageWindow, self.scalingName, "arcsinh","linear","sqrt", command=self.setRescaler)
self.scalingOption.grid(row=0, column=1)
rescaleLabel = Tk.Label(self.ImageWindow, text="Rescale: ")
rescaleLabel.grid(row=1, column=0)
self.scaleValue = Tk.Scale(self.ImageWindow, from_=-4, to=6, resolution=0.05, orient=Tk.HORIZONTAL, showvalue=1, length=300)
self.scaleValue.set(1.0)
self.scaleValue.grid(row=1, column=1)
minLabel = Tk.Label(self.ImageWindow, text="Min Pixel Value: ")
minLabel.grid(row=2, column=0)
self.minValue = Tk.Scale(self.ImageWindow, resolution=0.05, orient=Tk.HORIZONTAL, showvalue=1, length=300)
self.minValue.set(1.0)
self.minValue.grid(row=2, column=1)
maxLabel = Tk.Label(self.ImageWindow, text="Max Pixel Value: ")
maxLabel.grid(row=3, column=0)
self.maxValue = Tk.Scale(self.ImageWindow, resolution=0.05, orient=Tk.HORIZONTAL, showvalue=1, length=300)
self.maxValue.set(1.0)
self.maxValue.grid(row=3, column=1)
# Set the min/max slider boundaries
self.minValue.config(from_=self.rawData.min(), to=self.rawData.max())
self.minValue.set(self.rawData.min())
self.maxValue.config(from_=self.rawData.min(), to=self.rawData.max())
self.maxValue.set(self.rawData.max())
# Set the default rescaler
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)
#.........这里部分代码省略.........
示例2: wishbone_gui
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import grid [as 别名]
class wishbone_gui(tk.Tk):
def __init__(self,parent):
tk.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
self.vals = None
self.currentPlot = None
#set up menu bar
self.menubar = tk.Menu(self)
self.fileMenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="File", menu=self.fileMenu)
self.fileMenu.add_command(label="Load data", command=self.loadData)
self.fileMenu.add_command(label="Save data", state='disabled', command=self.saveData)
self.fileMenu.add_command(label="Exit Wishbone", command=self.quitWB)
self.analysisMenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Analysis", menu=self.analysisMenu)
self.analysisMenu.add_command(label="Principal component analysis", state='disabled', command=self.runPCA)
self.analysisMenu.add_command(label="tSNE", state='disabled', command=self.runTSNE)
self.analysisMenu.add_command(label="Diffusion map", state='disabled', command=self.runDM)
self.analysisMenu.add_command(label="GSEA", state='disabled', command=self.runGSEA)
self.analysisMenu.add_command(label="Wishbone", state='disabled', command=self.runWishbone)
self.visMenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Visualization", menu=self.visMenu)
self.visMenu.add_command(label="Principal component analysis", state='disabled', command=self.plotPCA)
self.visMenu.add_command(label="tSNE", state='disabled', command=self.plotTSNE)
self.visMenu.add_command(label="Diffusion map", state='disabled', command=self.plotDM)
self.visMenu.add_command(label="GSEA Results", state='disabled', command=self.showGSEAResults)
self.wishboneMenu = tk.Menu(self)
self.visMenu.add_cascade(label="Wishbone", menu=self.wishboneMenu)
self.wishboneMenu.add_command(label="On tSNE", state='disabled', command=self.plotWBOnTsne)
self.wishboneMenu.add_command(label="Marker trajectory", state='disabled', command=self.plotWBMarkerTrajectory)
self.wishboneMenu.add_command(label="Heat map", state='disabled', command=self.plotWBHeatMap)
self.visMenu.add_command(label="Gene expression", state='disabled', command=self.plotGeneExpOntSNE)
self.visMenu.add_command(label="Set gate", state='disabled', command=self.setGate)
self.config(menu=self.menubar)
#intro screen
tk.Label(self, text=u"Wishbone", font=('Helvetica', 48), fg="black", bg="white", padx=100, pady=50).grid(row=0)
tk.Label(self, text=u"To get started, select a data file by clicking File > Load Data", fg="black", bg="white", padx=100, pady=25).grid(row=1)
#update
self.protocol('WM_DELETE_WINDOW', self.quitWB)
self.grid_columnconfigure(0,weight=1)
self.resizable(True,True)
self.update()
self.geometry(self.geometry())
self.focus_force()
def loadData(self):
self.dataFileName = filedialog.askopenfilename(title='Load data file', initialdir='~/.wishbone/data')
if(self.dataFileName != ""):
#pop up data options menu
self.fileInfo = tk.Toplevel()
self.fileInfo.title("Data options")
tk.Label(self.fileInfo, text=u"File name: ").grid(column=0, row=0)
tk.Label(self.fileInfo, text=self.dataFileName.split('/')[-1]).grid(column=1, row=0)
tk.Label(self.fileInfo,text=u"Name:" ,fg="black",bg="white").grid(column=0, row=1)
self.fileNameEntryVar = tk.StringVar()
tk.Entry(self.fileInfo, textvariable=self.fileNameEntryVar).grid(column=1,row=1)
if self.dataFileName.split('.')[len(self.dataFileName.split('.'))-1] == 'fcs':
tk.Label(self.fileInfo,text=u"Cofactor:" ,fg="black",bg="white").grid(column=0, row=2)
self.cofactorVar = tk.IntVar()
self.cofactorVar.set(5)
tk.Entry(self.fileInfo, textvariable=self.cofactorVar).grid(column=1,row=2)
elif self.dataFileName.split('.')[len(self.dataFileName.split('.'))-1] == 'csv':
self.normalizeVar = tk.BooleanVar()
tk.Checkbutton(self.fileInfo, text=u"Normalize", variable=self.normalizeVar).grid(column=0, row=2, columnspan=2)
tk.Label(self.fileInfo, text=u"The normalize parameter is used for correcting for library size among cells.").grid(column=0, row=3, columnspan=2)
tk.Button(self.fileInfo, text="Cancel", command=self.fileInfo.destroy).grid(column=0, row=4)
tk.Button(self.fileInfo, text="Load", command=self.processData).grid(column=1, row=4)
self.wait_window(self.fileInfo)
def processData(self):
#clear intro screen
for item in self.grid_slaves():
item.grid_forget()
#display file name
tk.Label(self,text=u"File name: " + self.fileNameEntryVar.get(), fg="black",bg="white").grid(column=0,row=0)
#set up canvas for plots
self.fig, self.ax = wishbone.wb.get_fig()
self.canvas = FigureCanvasTkAgg(self.fig, self)
self.canvas.show()
self.canvas.get_tk_widget().grid(column=1, row=1, rowspan=10, columnspan=4,sticky='NSEW')
tk.Label(self, text=u"Visualizations:", fg='black', bg='white').grid(column=0, row=1)
#load data based on input type
if self.dataFileName.split('.')[len(self.dataFileName.split('.'))-1] == 'fcs': # mass cytometry data
#.........这里部分代码省略.........