当前位置: 首页>>代码示例>>Python>>正文


Python FigureCanvasTkAgg.draw_idle方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.draw_idle方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasTkAgg.draw_idle方法的具体用法?Python FigureCanvasTkAgg.draw_idle怎么用?Python FigureCanvasTkAgg.draw_idle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_tkagg.FigureCanvasTkAgg的用法示例。


在下文中一共展示了FigureCanvasTkAgg.draw_idle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PieChartView

# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import draw_idle [as 别名]
class PieChartView(tk.Frame):
    canvas = None
    controller = None
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self, text="Pie chart", font=LARGE_FONT)
        label.pack(pady=10, padx=10)
        labels = 'Positive', 'Neutral', 'Negative'
        amount = [pos, neut, neg]
        print(amount)
        colors = ['green', 'lightskyblue', 'red']
        explode = (0, 0.05, 0)  # proportion with which to offset each
        # wedge
        entry1 = ttk.Entry(self)
        entry1.pack()
        button3 = ttk.Button(self, text="Start stream ",
                             command=lambda: controller.start_stream(
                                 entry1.get()))
        button3.pack()

        piechart.pie(amount,  # data
                     explode=explode,  # offset parameters
                     labels=labels,  # slice labels
                     colors=colors,  # array of colours
                     autopct='%1.1f%%',  # print the values inside the wedges
                     shadow=True,  # enable shadow
                     startangle=70  # starting angle
                     )
        piechart.axis('equal')
        button1 = ttk.Button(self, text="Back to Home",
                             command=lambda: self.stop())
        button1.pack()
        self.canvas = FigureCanvasTkAgg(figure2, self)
        self.canvas.draw()

        self.canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH,
                                         expand=True)

        self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
    '''
    Roept de stop functie aan op de controller, en gaat terug naar de
    startpagina
    '''
    def stop(self):
        self.controller.show_frame(WelcomePage)
        self.controller.controller.stop_stream()
    '''
    Zorgt ervoor dat de pie chart de nieuwe waarden gebruikt
    '''
    def update(self):
        piechart.clear()
        piechart.pie([pos, neut, neg])
        self.canvas.draw_idle()
开发者ID:Jordan023,项目名称:sentiment,代码行数:56,代码来源:Views.py

示例2: NetworkPlotTk

# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import draw_idle [as 别名]
class NetworkPlotTk(KWallNetworkPlotBase):
    """
    This class implements UIs using Tkinter. 
    
    The content of this class is independent of the parent class.
    It only depends on the grandparent class, which should be
    'NetworkPlotBase'. Therefore this class can inherit any class
    whose parent is 'NetworkPlotBase'; just change the name of the
    parent in the definition of this class.
    """
    def __init__(self, 
        master=None,
        title=None,
    ):
        super(NetworkPlotTk, self).__init__(
            matplotlib_figure=matplotlib.figure.Figure(),
        )

        if master is None:
            master = tk.Tk()
            master.withdraw()
        self.master = master
        #self.master.protocol("WM_DELETE_WINDOW", self.on_closing)

        # Create a Toplevel widget, which is a child of GUILoom 
        # and contains plots,
        self.toplevel = tk.Toplevel(master)
        self.toplevel.wm_title(title)
        self.toplevel.protocol("WM_DELETE_WINDOW", self.on_closing)

        self.plot_idx_scale = None

        self.plot_idx_entry = None
        self.plot_idx_entry_var = tk.StringVar() 
        self.plot_idx_entry_var.trace('w', self.plot_idx_entry_change)

        self.canvas = FigureCanvas(
            self.figure,
            master=self.toplevel,
            resize_callback=self.canvas_resize_callback
        )
        self.canvas.show()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)

        toolbar = NavigationToolbar(self.canvas, self.toplevel)
        toolbar.update()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
   


    def on_closing(self):
        self.toplevel.destroy()
        self.master.destroy()


    def scale_action(self, scale_value):
        new_plot_idx = int(scale_value)
        self.update_current_plot(new_plot_idx)
        self.plot_idx_entry_var.set(new_plot_idx)


    def plot_idx_entry_change(self, *args):
        try:
            new_plot_idx = int(self.plot_idx_entry_var.get())

            if new_plot_idx == self.current_plot_idx:
                return None
            elif new_plot_idx < 0:
                new_plot_idx = 0
            elif new_plot_idx > len(self.plots) - 1:
                new_plot_idx = len(self.plots) - 1

            self.plot_idx_scale.set(new_plot_idx)
            self.update_current_plot(new_plot_idx)

        except ValueError:
            pass

        return None

    def update_current_plot(self, new_plot_idx):
        if self.data_cursor is not None:
            self.data_cursor.hide().disable()

        self.plots[self.current_plot_idx].set_visible(False)
        self.plots[new_plot_idx].set_visible(True)
        # Update the index variable for the currently displayed plot.
        self.current_plot_idx = new_plot_idx
        self.set_data_cursor()
        self.canvas.draw_idle()
        self.canvas.get_tk_widget().focus_set()

        return None


    def canvas_resize_callback(self, event):
        self.set_data_cursor()


    def show(self):
#.........这里部分代码省略.........
开发者ID:chan-y-park,项目名称:mose,代码行数:103,代码来源:plotting.py

示例3: __init__

# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import draw_idle [as 别名]

#.........这里部分代码省略.........
        self.fig = Figure(figsize=(7, 7))
        self.ax = self.fig.add_subplot(111)
        
        self.strainButton = tk.Button(self.frame, text="do", command=self.strainMap)

        self.canvas = FigureCanvasTkAgg(self.fig, master=self.frame)
        self.canvas.show()
        self.canvas.get_tk_widget().grid(row=0)
        self.canvas.mpl_connect('key_press_event', self.onKey)
        self.strainButton.grid(row=1)
        
        self.mask = np.zeros((512,512))
        self.pix = np.arange(512)
        self.XX, self.YY = np.meshgrid(self.pix, self.pix)
        self.pix = np.vstack((self.XX.flatten(), self.YY.flatten())).T
        self.lasso = LassoSelector(self.ax, self.onselect)
        
        
        
    def do(self):
        self.canvas.mpl_connect('key_press_event', self.onKey)
        self.ax.imshow(self.im, cmap = plt.cm.gray)
        

    def strainMap(self):

        zipped = zip(self.sampleArray, self.openArray)
        transmitted = np.zeros((len(zipped),1,512*512)).astype(np.float32)
        
        l = 0
        kernel = np.ones((5,5))
        kernel = kernel / kernel.sum()
        for sample, empty in zipped:
            sample = sample * self.mask.reshape(512,512)
            empty = empty * self.mask.reshape(512,512)
            
            transmitted[l] = convolve2d(sample, kernel, mode='same').flatten() / convolve2d(empty, kernel, mode='same').flatten()
            l += 1
            print l
        
        lambdas = []
        for c in range(512*512):
            if transmitted[:,:,c][posList[0]:posList[-1]].all() == False:
                lambdas.append(0)
                print 'empty'

            else:
                try:
                    popt, pcov = curve_fit(self.func, wavelength[posList[0]:posList[-1]+1], np.dstack(np.nan_to_num(transmitted[:,:,c][posList[0]:posList[-1]+1]))[0][0], p0=initial_guess)
                
                    lambdas.append((initial_guess[2] - popt[2])/initial_guess[2])
                    print 'full'
                    "fit Bragg edge, record position"
                except (OptimizeWarning, RuntimeError):
                    lambdas.append((initial_guess[2] - popt[2])/initial_guess[2])
                    print 'Exception'
                
                
        strainMap = np.array(lambdas).reshape(512,512)*self.mask.reshape(512,512) 
        strainMap = np.ma.masked_where(strainMap == 0, strainMap)
        minVal = strainMap.min()
        maxVal = strainMap.max()
        cmap = plt.cm.coolwarm
        cmap.set_bad(color='black')
        fig = plt.figure()
        ax = fig.add_subplot(111)
        cax = ax.imshow(strainMap, interpolation='None', cmap=cmap)
        cbar = fig.colorbar(cax, ticks=[minVal, 0, maxVal])
        cbar.ax.set_yticklabels(['< '+minVal, '0', '> '+maxVal])
        plt.show()
        plt.close()
                
    def func(self, x, c_1, c_2, lambda0, sigma, tau):
        return c_1 * (scipy.special.erfc((lambda0 - x) / (np.sqrt(2) * sigma)) - np.exp(
            ((lambda0 - x) / tau) + (sigma ** 2 / (2 * tau ** 2))) * scipy.special.erfc(
            ((lambda0 - x) / (np.sqrt(2) * sigma)) + sigma / (np.sqrt(2) * tau))) + c_2   
        
    def updateArray(self, im, indices,mask):
        lin = np.arange(self.im.size)
        self.mask = self.mask.flatten()
        self.mask[lin[indices]] = 1
        newArray = im.flatten()
        #newArray[lin[indices]] = 1
        newArray = newArray*self.mask
        self.ax.imshow(newArray.reshape(self.im.shape), cmap=plt.cm.gray)
        self.canvas.draw()
        print self.mask
        return newArray.reshape(self.im.shape)

    def onselect(self, verts):
        p = path.Path(verts)
        ind = p.contains_points(self.pix, radius=1)
        array = self.updateArray(self.im, ind, self.mask)
        self.canvas.draw_idle()
        
    def onKey(self, event):
        print "key pressed"
        if event.key == 'r':
            self.ax.imshow(self.im, cmap=plt.cm.gray)
            self.canvas.draw()
开发者ID:jm22b,项目名称:Bragg-Edge-Analysis,代码行数:104,代码来源:BraggEdgeAnalysisV4.0.0.py


注:本文中的matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.draw_idle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。