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


Python FigureCanvasQTAgg.close方法代码示例

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


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

示例1: VisualizerDialog

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import close [as 别名]
class VisualizerDialog(QtWidgets.QWidget):
    """ Defines a QDialog that is used to visualize the data in the main
    data preview area. It connects the dataChanged signal of the abstract
    data table and the sectionMoved signal of the header of the table view to
    the update_plot() method so that the method is called whenever either the
    content of the results table changes, or the columns are moved.

    The visualizer dialog has a 'Freeze visualization' checkbox. If the box
    is checked, the visualization is not updated on changes.

    FIXME: Live updates are currently disabled.
    """
    def __init__(self, parent=None):
        super(VisualizerDialog, self).__init__(parent)

        self.ui = Ui_Visualizer()
        self.ui.setupUi(self)
        self.ui.progress_bar.setRange(0, 0)
        self.ui.box_visualize.hide()
        self.ui.progress_bar.hide()
        self.ui.label.hide()

        self.setWindowIcon(options.cfg.icon)
        self.margin_dialoglog_stack = []

        self.frozen = False
        self.spinner = QtWidgets.QSpinBox()
        self.spinner.setFrame(True)
        self.spinner.setButtonSymbols(QtWidgets.QAbstractSpinBox.UpDownArrows)
        self.spinner.setMaximum(10)
        self.spinner.setMinimum(1)
        self.spinner.setSuffix(" year(s)")
        self.spinner_label = QtWidgets.QLabel("Bandwidth: ")
        self.spinner.valueChanged.connect(self.update_plot)

        self.combo_x_function = QtWidgets.QComboBox()
        self.label_x_function = QtWidgets.QLabel("Variable on &X axis:")
        self.label_x_function.setBuddy(self.combo_x_function)
        self.combo_y_function = QtWidgets.QComboBox()
        self.label_y_function = QtWidgets.QLabel("Variable on &Y axis:")
        self.label_y_function.setBuddy(self.combo_y_function)

        self.toolbar = None
        self.canvas = None

        try:
            self.resize(options.settings.value("visualizer_size"))
        except TypeError:
            pass

    def closeEvent(self, event):
        options.settings.setValue("visualizer_size", self.size())
        self.close()

    def update_plot(self):
        """
        Update the plot.

        During the update, the canvas and the navigation toolbar are
        replaced by new instances, as is the figure used by the visualizer.
        Finally, the draw() method of the visualizer is called to plot the
        visualization again.
        """
        if hasattr(self.toolbar, "margin_dialog"):
            self.toolbar.margin_dialog.hide()
            self.toolbar.margin_dialog.close()
            get_toplevel_window().widget_list.remove(self.toolbar.margin_dialog)
            del self.toolbar.margin_dialog

        if self.smooth:
            self.spinner.setEnabled(False)
            self.visualizer.update_data(bandwidth=self.spinner.value())
        else:
            self.visualizer.update_data()


        kwargs = {}
        if self.visualizer.numerical_axes == 2:
            try:
                kwargs["func_y"] = self._function_list[self.combo_y_function.currentIndex()]
                kwargs["column_y"] = None
            except IndexError:
                kwargs["func_y"] = None
                kwargs["column_y"] = utf8(self.combo_y_function.currentText())
        if self.visualizer.numerical_axes == 1:
            try:
                kwargs["func_x"] = self._function_list[self.combo_x_function.currentIndex()]
                kwargs["column_x"] = None
            except IndexError:
                kwargs["func_x"] = None
                kwargs["column_x"] = utf8(self.combo_x_function.currentText())

        self.visualizer.setup_figure()

        self.remove_matplot()
        self.add_matplot()

        self.visualizer.draw(**kwargs)

        self.visualizer.g.fig.tight_layout()
#.........这里部分代码省略.........
开发者ID:gkunter,项目名称:coquery,代码行数:103,代码来源:visualization.py

示例2: close

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import close [as 别名]
    def close(self, *args, **kwargs):
        for widget in [self.toolbar, self.smartScale, self.VCursor]:
            widget.close()
            widget.deleteLater()

        FigureCanvas.close(self, *args, **kwargs)
开发者ID:Subaru-PFS,项目名称:ics_sps_engineering_plotData,代码行数:8,代码来源:graph.py

示例3: SigmaSwiperProgram

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import close [as 别名]

#.........这里部分代码省略.........
                    self.guest_list_check_label.setStyleSheet('color: red')
                    self.id_input.clear()
                else:
                    self.count +=1
                    self.graph_y.append(self.count)
                    self.data["ID"].append(inp)
                    self.data["TIME"].append(datetime.datetime.now().strftime("%H:%M"))
                    self.graph_x.append(datetime.datetime.now().strftime("%H:%M:%S"))
                    name =self.guest_list["NAME"][self.guest_list["ID"].index(int(inp))]
                    self.data["NAME"].append(name)
                    self.guest_list_check_label.setText("On List")
                    self.guest_list_check_label.setStyleSheet('color: green')
                    self.lcdNumber.display(self.count)
                    self.list_preview.addItem(name+" - "+inp)
                    self.plot_data()
                    #if self.count % 10 == 0:
                     #   export = pd.DataFrame(self.data)        
                      #  export.index += 1
                       # fname =  os.path.expanduser('~')+"/Desktop/temp.xlsx"
                        #export.to_excel(fname[0])
            else:
                self.guest_list_check_label.setText("No Guest List Loaded")
                self.guest_list_check_label.setStyleSheet('color: yellow')
                self.id_input.clear()
        else:
            self.guest_list_check_label.setText("Invalid Input")
            self.guest_list_check_label.setStyleSheet('color: yellow')
        self.id_input.clear()

    def email_list(self,file_path):
        if self.settings["send_email"] == "yes":
            for x in self.settings["to_email"].strip().split(','):
                try:
                    toaddr = x.strip()
                    fromaddr = self.settings["from_email"]

                    msg = MIMEMultipart()
                    msg['From'] = fromaddr
                    msg['To'] = toaddr
                    msg['Subject'] = "Party List for "+self.today

                    body = "Hello,\n Attached is the attendance sheet for our social event on "+self.today+". If any additional information is needed, please contact <insert responsible person here>"

                    msg.attach(MIMEText(body, 'plain'))
                    filename = file_path.split("/")[-1]
                    attachment = open(file_path, "rb")
                    part = MIMEBase('application', 'octet-stream')
                    part.set_payload((attachment).read())
                    encoders.encode_base64(part)
                    part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
                    msg.attach(part)
                    server = smtplib.SMTP('smtp.gmail.com', 587)
                    server.starttls()
                    server.login(fromaddr, self.settings["email_password"])
                    text = msg.as_string()
                    server.sendmail(fromaddr, toaddr, text)
                    server.quit()
                except:
                    print("email error")
                    pass
        else:
            pass
    def export_data(self):
        export = pd.DataFrame(self.data)
        export.index += 1
        fname = QFileDialog.getSaveFileName(None, 'Save Guest Log' , os.path.expanduser('~')+"/Desktop/"+self.today+"-"+self.settings["default_filename"]+".xlsx","Excel Files (*.xlsx)" )
        if fname[0] == '':
            pass
        else:
            export.to_excel(fname[0])
        self.email_list(fname[0])
    def plot_data(self):
        if not self.has_graph:
            new_x = [mdates.datestr2num(x) for x in self.graph_x]
            plt.xlabel('Time')
            plt.ylabel('Count')
            ax = self.fig.add_subplot(111)
            ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
            ax.plot(new_x, self.graph_y, 'r-')
            ax.get_xaxis().set_ticks([])
            #ax.get_yaxis().set_ticks([])
            self.canvas = FigureCanvas(self.fig)
            self.graph_layout.addWidget(self.canvas)
            self.canvas.draw()
            self.has_graph = True
        else:
            self.graph_layout.removeWidget(self.canvas)
            self.canvas.close()
            self.fig.clf()
            plt.xlabel('Time')
            plt.ylabel('Count')
            ax = self.fig.add_subplot(111)
            ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
            new_x = [mdates.datestr2num(x) for x in self.graph_x]
            ax.plot(new_x, self.graph_y, 'r-')
            ax.get_xaxis().set_ticks([])
            #ax.get_yaxis().set_ticks([])
            self.canvas = FigureCanvas(self.fig)
            self.graph_layout.addWidget(self.canvas)
            self.canvas.draw()
开发者ID:jshodd,项目名称:SigmaSwiper,代码行数:104,代码来源:sigmaSwiper.py

示例4: Main

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import close [as 别名]
class Main(QMainWindow, Ui_MainWindow):
    def __init__(self,specfilename,parfilename=None,wave1=None,wave2=None,numchunks=8,parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)
        #super(Main,self).__init__()
        self.setupUi(self)

        ### Initialize stuff
        self.line_dict = {}
        self.fitpars = None
        self.parinfo = None
        self.linecmts = None
        self.wave1 = wave1
        self.wave2 = wave2
        self.numchunks = numchunks
        self.spls = []
        self.labeltog = 1
        self.pixtog = 0
        self.restog = 1
        self.fitconvtog = 0
        self.lastclick=1334.

        ### Read in spectrum and list of lines to fit
        self.specfilename=specfilename
        self.spectrum = readspec(specfilename)
        self.wave=self.spectrum.wavelength.value
        self.normflux=self.spectrum.flux/self.spectrum.co
        self.normsig=self.spectrum.sig/self.spectrum.co
        cfg.spectrum = self.spectrum
        cfg.wave=self.wave
        cfg.normflux=self.normflux
        cfg.filename=self.specfilename

        if not parfilename==None:
            self.initialpars(parfilename)


        ### Connect signals to slots
        self.fitButton.clicked.connect(self.fitlines)
        self.fitConvBox.clicked.connect(self.togfitconv)
        self.boxLineLabel.clicked.connect(self.toglabels)
        self.boxFitpix.clicked.connect(self.togfitpix)
        self.boxResiduals.clicked.connect(self.togresiduals)
        self.loadParsButton.clicked.connect(self.openParFileDialog)
        self.addLineButton.clicked.connect(self.addLineDialog)
        self.writeParsButton.clicked.connect(self.writeParFileDialog)
        self.writeModelButton.clicked.connect(self.writeModelFileDialog)
        self.writeModelCompButton.clicked.connect(self.writeModelCompFileDialog)
        self.quitButton.clicked.connect(self.quitGui)

        ### Initialize spectral plots
        fig=Figure()
        self.fig=fig
        self.initplot(fig)

        ### Initialize side plot
        sidefig=Figure(figsize=(5.25,2))
        self.sidefig = sidefig
        self.addsidempl(self.sidefig)
        self.sideplot(self.lastclick)  #Dummy initial cenwave setting


    def initplot(self,fig,numchunks=8):
        wlen=len(self.spectrum.wavelength)/numchunks
        self.spls=[]
        if self.wave1==None:  waveidx1=0  # Default to plotting entire spectrum for now
        else: waveidx1=jbg.closest(self.wave,self.wave1)
        if self.fitpars!=None:
                model=joebvpfit.voigtfunc(self.wave,self.datamodel.fitpars)
        sg=jbg.subplotgrid(numchunks)
        for i in range(numchunks):
            self.spls.append(fig.add_subplot(sg[i][0],sg[i][1],sg[i][2]))
            pixs=range(waveidx1+i*wlen,waveidx1+(i+1)*wlen)
            self.spls[i].plot(self.wave[pixs],self.normflux[pixs],linestyle='steps-mid')
            if self.fitpars!=None:
                self.spls[i].plot(self.wave,model,'r')
            self.spls[i].set_xlim(self.wave[pixs[0]],self.wave[pixs[-1]])
            self.spls[i].set_ylim(cfg.ylim)
            self.spls[i].set_xlabel('wavelength',labelpad=0)
            self.spls[i].set_ylabel('relative flux',labelpad=-5)
            self.spls[i].get_xaxis().get_major_formatter().set_scientific(False)
        fig.subplots_adjust(top=0.98,bottom=0.05,left=0.08,right=0.97,wspace=0.15,hspace=0.25)
        self.addmpl(fig)

    def initialpars(self,parfilename):
        ### Deal with initial parameters from line input file
        self.fitpars,self.fiterrors,self.parinfo,self.linecmts = joebvpfit.readpars(parfilename)
        cfg.fitidx=joebvpfit.fitpix(self.wave, self.fitpars) #Set pixels for fit
        cfg.wavegroups=[]
        self.datamodel = LineParTableModel(self.fitpars,self.fiterrors,self.parinfo,linecmts=self.linecmts)
        self.tableView.setModel(self.datamodel)
        self.datamodel.updatedata(self.fitpars,self.fitpars,self.parinfo,self.linecmts)

    def sideplot(self,cenwave,wavebuf=3):
        if len(self.sidefig.axes)==0:
            self.sideax=self.sidefig.add_subplot(111)
        self.sideax.clear()
        self.sideax.plot(self.wave, self.normflux, linestyle='steps-mid')
        if self.pixtog == 1:
            self.sideax.plot(self.wave[cfg.fitidx], self.normflux[cfg.fitidx], 'gs', markersize=4, mec='green')
        model = joebvpfit.voigtfunc(self.wave, self.fitpars)
#.........这里部分代码省略.........
开发者ID:ntejos,项目名称:joebvp,代码行数:103,代码来源:VPmeasure.py

示例5: Main

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import close [as 别名]

#.........这里部分代码省略.........
                self.im.set_ydata(self.X.data[self.Scroll_Horz.value(), :, self.Scroll_Vert.value()][::])
                if self.auto_flag:
                    self.ax1.relim()
                    self.ax1.autoscale_view(True, True, True)
            elif self.BoreView == 'Z':
                self.im.set_ydata(self.X.data[self.Scroll_Vert.value(), self.Scroll_Horz.value(), :][::])
                if self.auto_flag:
                    self.ax1.relim()
                    self.ax1.autoscale_view(True, True, True)
        elif self.AverageBore.isChecked():
            self.Scroll_Horz.setValue(self.ind)
            self.Scroll_Vert.setValue(self.ind)

        # try and redraw
        try:
            self.im.axes.figure.canvas.draw()
            if self.auto_flag:
                self.im.autoscale()
        except AttributeError:
            pass

    def addmpl(self):
        # add plot to anvas
        self.rmmpl()
        self.canvas = FigureCanvas(self.fig)
        self.mplvl.addWidget(self.canvas)
        self.canvas.draw()
        self.toolbar = NavigationToolbar(self.canvas, self.mplwindow)
        self.mplvl.addWidget(self.toolbar)

    def rmmpl(self):
        # delete plot from canvas
        try:
            self.canvas.close()
            self.canvas.deleteLater()
            self.toolbar.close()
            self.toolbar.deleteLater()
            gc.collect()
        except:
            pass

    def saveBore(self,):
        # save bore as a list of points
        name = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File')
        f = open(name, 'w')
        if len(self.ave) > 1:
            for i in range(len(self.ave)):
                f.write(str(self.ave[i]) + '\n')
            f.close()
        else:
            if self.BoreView == "X":
                tmp = self.X[:, self.Scroll_Horz.value(), self.Scroll_Vert.value()]
            elif self.BoreView == "Y":
                tmp = self.X[self.Scroll_Horz.value(), :, self.Scroll_Vert.value()]
            elif self.BoreView == "Z":
                tmp = self.X[self.Scroll_Horz.value(), self.Scroll_Vert.value(), :]

            for i in range(len(tmp)):
                f.write(str(tmp[i]) + '\n')

    def file_open(self, args):

        self.reset_plot()

        while True:
            try:
开发者ID:lewisfish,项目名称:data_cube_viewer,代码行数:70,代码来源:custommpl.py


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