Ejemplo n.º 1
0
    def __init__(self, plot_path, plot_config_path):
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.plot_figure = PlotFigure()
        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        size = QSize(297*2, 210*2) # A4 aspectratio
        self.canvas.setMaximumSize(size)
        self.canvas.setMinimumSize(size)
        self.setMaximumSize(size)
        self.setMinimumSize(size)

        self.popup = Popup(self)
        self.plot_config_loader = PlotSettingsLoader()
        self.plot_settings = PlotSettings()
        self.plot_settings.setPlotPath(plot_path)
        self.plot_settings.setPlotConfigPath(plot_config_path)
        self.connect(self.popup, SIGNAL('updateProgress(int)'), self.updateProgress)


        self.plot_context_data_fetcher = PlotContextDataFetcher()
        self.plot_context_data_fetcher.initialize(self.plot_context_data_fetcher.getModel())
        self.plot_data_fetcher = PlotDataFetcher()
        self.plot_data_fetcher.initialize(self.plot_data_fetcher.getModel())
Ejemplo n.º 2
0
 def test_read_file_all_wrong(self):
     data = "# SrU2F12 Raman spectrum\n# X = Freq (cm^-1); Y = Polycrystalline Raman intensity (arb. units)\n50     plop\nplip        100\n         plop         100\n\n\n200 jhhhh hkhh\n    plop     300 \n400        500                600 \n"
     
     x = []          
     y = []
     
     self.canvas = PlotFigure()
     self.canvas.read_file(data)
     
     self.assertEqual(x, self.canvas.frequencies, "Wrong frequencies")
     self.assertEqual(y, self.canvas.intensities, "Wrong intensities")
Ejemplo n.º 3
0
 def test_read_file(self):
     data = "# SrU2F12 Raman spectrum\n# X = Freq (cm^-1); Y = Polycrystalline Raman intensity (arb. units)\n486.40      211.39\n494.64      78.15\n504.37      181.35\n513.02      68.03\n534.32      30.33\n646.23      1000\n653.24      13.5"        
     
     x = [486.40, 494.64, 504.37, 513.02, 534.32, 646.23, 653.24]          
     y = [211.39, 78.15, 181.35, 68.03, 30.33, 1000, 13.5]
     
     self.canvas = PlotFigure()
     self.canvas.read_file(data)
     
     self.assertEqual(x, self.canvas.frequencies, "Wrong frequencies")
     self.assertEqual(y, self.canvas.intensities, "Wrong intensities")
Ejemplo n.º 4
0
    def __init__(self):
        super().__init__()
        self.init_window()

        self.init_menubar()  # File-Open

        self.canvas = PlotFigure()
        self.hbox3.addWidget(self.canvas)

        self.toolbar = NavigationToolbar(self.canvas, self)
        self.hbox2.addWidget(self.toolbar)

        self.init_checkbox_peaks()
        self.hbox4.addStretch(1)
        self.init_textline_peak_width()
Ejemplo n.º 5
0
    def __init__(self, plot_path, plot_config_path):
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.plot_figure = PlotFigure()
        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        size = QSize(297*2, 210*2) # A4 aspectratio
        self.canvas.setMaximumSize(size)
        self.canvas.setMinimumSize(size)
        self.setMaximumSize(size)
        self.setMinimumSize(size)

        self.popup = Popup(self)
        self.plot_config_loader = PlotSettingsLoader()
        self.plot_settings = PlotSettings()
        self.plot_settings.setPlotPath(plot_path)
        self.plot_settings.setPlotConfigPath(plot_config_path)
        self.connect(self.popup, SIGNAL('updateProgress(int)'), self.updateProgress)


        self.plot_context_data_fetcher = PlotContextDataFetcher()
        self.plot_context_data_fetcher.initialize(self.plot_context_data_fetcher.getModel())
        self.plot_data_fetcher = PlotDataFetcher()
        self.plot_data_fetcher.initialize(self.plot_data_fetcher.getModel())
Ejemplo n.º 6
0
    def __init__(self):
        """Create a PlotView instance"""
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        # setup some default data values
        self.data = PlotData()
        self.data.x_data_type = "number"
        self.data.setValid(False)

        self.plot_figure = PlotFigure()
        self.plot_settings = PlotSettings()

        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.mouse_handler = MouseHandler(self)
Ejemplo n.º 7
0
    def __init__(self):
        """Create a PlotView instance"""
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        # setup some default data values
        self.data = PlotData()
        self.data.x_data_type = "number"
        self.data.setValid(False)

        self.plot_figure = PlotFigure()
        self.plot_settings = PlotSettings()

        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.mouse_handler = MouseHandler(self)
Ejemplo n.º 8
0
class Test(unittest.TestCase):
    
    def set_up(self):  
        self.canvas = PlotFigure()
        
    def test_read_file(self):
        data = "# SrU2F12 Raman spectrum\n# X = Freq (cm^-1); Y = Polycrystalline Raman intensity (arb. units)\n486.40      211.39\n494.64      78.15\n504.37      181.35\n513.02      68.03\n534.32      30.33\n646.23      1000\n653.24      13.5"        
        
        x = [486.40, 494.64, 504.37, 513.02, 534.32, 646.23, 653.24]          
        y = [211.39, 78.15, 181.35, 68.03, 30.33, 1000, 13.5]
        
        self.canvas = PlotFigure()
        self.canvas.read_file(data)
        
        self.assertEqual(x, self.canvas.frequencies, "Wrong frequencies")
        self.assertEqual(y, self.canvas.intensities, "Wrong intensities")
        
    def test_read_file_some_wrong(self):
        data = "# SrU2F12 Raman spectrum\n# X = Freq (cm^-1); Y = Polycrystalline Raman intensity (arb. units)\n50     plop\nplip        100\n         100         100\n\n\n200 jhhhh hkhh\n    300      300 \n400        500                600 \n"
        
        x = [100, 300]          
        y = [100, 300]
        
        self.canvas = PlotFigure()
        self.canvas.read_file(data)
        
        self.assertEqual(x, self.canvas.frequencies, "Wrong frequencies")
        self.assertEqual(y, self.canvas.intensities, "Wrong intensities")
        
    def test_read_file_all_wrong(self):
        data = "# SrU2F12 Raman spectrum\n# X = Freq (cm^-1); Y = Polycrystalline Raman intensity (arb. units)\n50     plop\nplip        100\n         plop         100\n\n\n200 jhhhh hkhh\n    plop     300 \n400        500                600 \n"
        
        x = []          
        y = []
        
        self.canvas = PlotFigure()
        self.canvas.read_file(data)
        
        self.assertEqual(x, self.canvas.frequencies, "Wrong frequencies")
        self.assertEqual(y, self.canvas.intensities, "Wrong intensities")
Ejemplo n.º 9
0
 def set_up(self):  
     self.canvas = PlotFigure()
Ejemplo n.º 10
0
class PlotView(QFrame):
    """PlotView presents a matplotlib canvas with interaction possibilities. (picking and tooltip)"""

    def __init__(self):
        """Create a PlotView instance"""
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        # setup some default data values
        self.data = PlotData()
        self.data.x_data_type = "number"
        self.data.setValid(False)

        self.plot_figure = PlotFigure()
        self.plot_settings = PlotSettings()

        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.mouse_handler = MouseHandler(self)

    def toggleMember(self, line):
        gid = int(line.get_gid())
        if gid in self.plot_settings.getSelectedMembers():
            self.plot_settings.unselectMember(gid)
        else:
            self.plot_settings.selectMember(gid)

    @ert_gui.widgets.util.may_take_a_long_time
    def drawPlot(self):
        self.plot_figure.drawPlot(self.data, self.plot_settings)
        self.canvas.draw()

    def resizeEvent(self, event):
        QFrame.resizeEvent(self, event)
        self.canvas.resize(event.size().width(), event.size().height())

    def loadSettings(self, name):
        if self.data.isValid():
            plot_config_loader = PlotSettingsLoader()
            if not plot_config_loader.load(name, self.plot_settings):
                self.drawPlot()

    def saveSettings(self):
        if self.data.isValid():
            plot_config_saver = PlotSettingsSaver()
            plot_config_saver.save(self.data.getSaveName(), self.plot_settings)

    def setData(self, data):
        self.saveSettings()

        self.data = data

        self.loadSettings(self.data.getSaveName())

    def setXZoomFactors(self, xminf, xmaxf):
        self.plot_settings.setMinXZoom(xminf)
        self.plot_settings.setMaxXZoom(xmaxf)

    def setYZoomFactors(self, yminf, ymaxf):
        self.plot_settings.setMinYZoom(yminf)
        self.plot_settings.setMaxYZoom(ymaxf)

    def save(self):
        self.saveSettings()

        plot_generator = PlotGenerator(self.plot_settings.getPlotPath(), self.plot_settings.getPlotConfigPath())
        plot_generator.save(self.data)

    def saveAll(self):
        self.saveSettings()

        plot_generator = PlotGenerator(self.plot_settings.getPlotPath(), self.plot_settings.getPlotConfigPath())
        plot_generator.saveAll()

    def copyPlotSettings(self):
        plot_config_loader = PlotSettingsLoader()
        plot_config_loader.copy(self.plot_settings)

    def setPlotPath(self, plot_path):
        self.plot_settings.setPlotPath(plot_path)

    def setPlotConfigPath(self, path):
        self.plot_settings.setPlotConfigPath(path)

    def _selectedMemberIdentifier(self, artist):
        return artist.get_gid() in self.plot_settings.getSelectedMembers()

    def clearSelection(self):
        selected_lines = self.plot_figure.fig.findobj(self._selectedMemberIdentifier)
        for line in selected_lines:
            self.plot_settings.unselectMember(line.get_gid())

    def displayToolTip(self, event):
        if not self.data is None and not event.xdata is None and not event.ydata is None:
            if self.data.getXDataType() == "time":
                date = matplotlib.dates.num2date(event.xdata)
                self.setToolTip("x: %s y: %04f" % (date.strftime("%d/%m-%Y"), event.ydata))
            else:
                self.setToolTip("x: %04f y: %04f" % (event.xdata, event.ydata))
        else:
            self.setToolTip("")

    def annotate(self, label, x, y, xt=None, yt=None):
        self.plot_settings.addAnnotation(label, x, y, xt, yt)

    def removeAnnotation(self, annotation_artist):
        annotations = self.plot_settings.getAnnotations()
        for annotation in annotations:
            if annotation.getUserData() == annotation_artist:
                self.plot_settings.removeAnnotation(annotation)

    def moveAnnotation(self, annotation_artist, xt, yt):
        annotations = self.plot_settings.getAnnotations()
        for annotation in annotations:
            if annotation.getUserData() == annotation_artist:
                annotation.xt = xt
                annotation.yt = yt

        annotation_artist.xytext = (xt, yt)

    def draw(self):
        self.canvas.draw()

    def setMinYLimit(self, value):
        self.plot_settings.setMinYLimit(value)

    def setMaxYLimit(self, value):
        self.plot_settings.setMaxYLimit(value)

    def setMinXLimit(self, value):
        self.plot_settings.setMinXLimit(value)

    def setMaxXLimit(self, value):
        self.plot_settings.setMaxXLimit(value)

    def getPlotConfigList(self):
        return self.plot_settings.getPlotConfigList()
Ejemplo n.º 11
0
class PlotGenerator(QFrame):

    def __init__(self, plot_path, plot_config_path):
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.plot_figure = PlotFigure()
        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        size = QSize(297*2, 210*2) # A4 aspectratio
        self.canvas.setMaximumSize(size)
        self.canvas.setMinimumSize(size)
        self.setMaximumSize(size)
        self.setMinimumSize(size)

        self.popup = Popup(self)
        self.plot_config_loader = PlotSettingsLoader()
        self.plot_settings = PlotSettings()
        self.plot_settings.setPlotPath(plot_path)
        self.plot_settings.setPlotConfigPath(plot_config_path)
        self.connect(self.popup, SIGNAL('updateProgress(int)'), self.updateProgress)


        self.plot_context_data_fetcher = PlotContextDataFetcher()
        self.plot_context_data_fetcher.initialize(self.plot_context_data_fetcher.getModel())
        self.plot_data_fetcher = PlotDataFetcher()
        self.plot_data_fetcher.initialize(self.plot_data_fetcher.getModel())

    def updateProgress(self, progress = 1):
        value = self.popup.progress_bar.value()
        self.popup.progress_bar.setValue(value + progress)

    def saveAll(self):
        self.popup.show()

        context_data = self.plot_context_data_fetcher.getFromModel()

        save_list = []
        count = 0
        for parameter in context_data.parameters:
            pt = parameter.type

            if pt == SummaryModel.TYPE or pt == KeywordModel.TYPE or pt == enums.obs_impl_type.FIELD_OBS:
                save_list.append(parameter)
                parameter.setUserData({'state' : enums.ert_state_enum.FORECAST})

                if pt == KeywordModel.TYPE:
                    choices = context_data.key_index_list[parameter.name]
                    parameter.getUserData()['key_index_choices'] = choices
                    count += len(choices)
                else:
                    count += 1


        self.popup.progress_bar.setMaximum(count)

        for parameter in save_list:
            if parameter.type == KeywordModel.TYPE:
                for choice in parameter.getUserData()['key_index_choices']:
                    self.plot_data_fetcher.setParameter(parameter, context_data)
                    parameter.getUserData()['key_index'] = choice # because setParameter overwrites this value
                    self.plot_data_fetcher.fetchContent()
                    self.savePlot(self.plot_data_fetcher.data)
            else:
                self.plot_data_fetcher.setParameter(parameter, context_data)
                self.plot_data_fetcher.fetchContent()
                self.savePlot(self.plot_data_fetcher.data)

        self.popup.ok_button.setEnabled(True)

    def save(self, plot_data):
        self.popup.show()

        self.popup.progress_bar.setMaximum(1)

        self.savePlot(plot_data)
        self.popup.ok_button.setEnabled(True)


    def savePlot(self, plot_data):
        generated_plot = self.generatePlot(plot_data)
        if generated_plot:
            self.savePlotToFile(plot_data.getSaveName())
        self.popup.emit(SIGNAL('updateProgress(int)'), 1)

    def generatePlot(self, plot_data):
        name = plot_data.getSaveName()
        load_success = self.plot_config_loader.load(name, self.plot_settings)

        if load_success:
            self.plot_figure.drawPlot(plot_data, self.plot_settings)
            self.canvas.draw()

        return load_success

    def savePlotToFile(self, filename):
        """Save the plot visible in the figure."""
        plot_path = self.plot_settings.getPlotPath()
        if not os.path.exists(plot_path):
            os.makedirs(plot_path)

        path = plot_path + "/" + filename
        self.plot_figure.getFigure().savefig(path + ".png", dpi=400, format="png")
        self.plot_figure.getFigure().savefig(path + ".pdf", dpi=400, format="pdf")
Ejemplo n.º 12
0
class GUI(QMainWindow):
    '''
    The class GUI handles the drawing of a PlotFigure and allows user to
    interact with it.
    '''
    def __init__(self):
        super().__init__()
        self.init_window()

        self.init_menubar()  # File-Open

        self.canvas = PlotFigure()
        self.hbox3.addWidget(self.canvas)

        self.toolbar = NavigationToolbar(self.canvas, self)
        self.hbox2.addWidget(self.toolbar)

        self.init_checkbox_peaks()
        self.hbox4.addStretch(1)
        self.init_textline_peak_width()

    def init_textline_peak_width(self):
        '''
        Textline for changing the peak width
        '''
        self.title = QLabel(self)
        self.title.setText('Peak Width:')
        self.hbox4.addWidget(self.title)
        self.tline = QLineEdit(self)
        self.tline.setMaxLength(3)
        self.hbox4.addWidget(self.tline)
        self.tline.returnPressed.connect(self.onPressed)

    def onPressed(self):
        '''
        Draws a new figure to canvas according to the given FWHM
        '''
        self.canvas.set_fwhm(float(self.tline.text()))
        if self.canvas.file_loaded:  # Only if a text file has been loaded even once, try could be better
            self.canvas.clear_axes()
            if self.canvas.peaks_checked:
                self.canvas.draw_stem_plot()
            self.canvas.draw_simulated_plot()
            self.canvas.draw()

    def init_menubar(self):
        '''
        For opening the text file. 
        '''
        openFile = QAction(QIcon('open.png'), 'Open', self)
        openFile.setShortcut('Ctrl+O')
        openFile.setStatusTip('Open new File')
        openFile.triggered.connect(self.showDialog_load)

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(openFile)

    def showDialog_load(self):
        '''
        Opens the file as string and conveys it to the canvas for drawing the plots.
        '''
        fname = QFileDialog.getOpenFileName(self, 'Open file', '/home')

        if fname[0]:
            try:
                f = open(fname[0], 'r')
                with f:  # with takes care of closing the file too
                    data = f.read()
                    self.canvas.load_file(data)
                    self.canvas.draw()
            except OSError:
                print("Could not open the file")  # Does not print this

    def init_checkbox_peaks(self):
        '''
        Peaks on/off selection
        '''
        self.checkBox = QCheckBox('Peaks', self)
        self.checkBox.toggle()
        self.checkBox.stateChanged.connect(self.peaks_on_off)

        self.hbox4.addWidget(self.checkBox)

    def peaks_on_off(self, state):
        if state == Qt.Checked:
            self.canvas.set_peaks_on()
            if self.canvas.file_loaded:  # Only if a text file has been loaded even once, try better?
                self.canvas.draw_stem_plot()
                self.canvas.draw()
        else:
            self.canvas.set_peaks_off()
            if self.canvas.file_loaded:
                self.canvas.clear_axes()
                self.canvas.draw_simulated_plot()
                self.canvas.draw()

    def init_window(self):
        #Sets up the window.
        title = "Spectrum Simulation"
        top = 400
        left = 400
        width = 900
        height = 600
        self.setWindowTitle(title)
        self.setGeometry(top, left, width, height)

        self.setCentralWidget(QtWidgets.QWidget(
        ))  # QMainWindown must have a centralWidget to be able to add layouts
        self.vbox = QtWidgets.QVBoxLayout()  # Vertical main layout
        self.centralWidget().setLayout(self.vbox)
        self.hbox1 = QtWidgets.QHBoxLayout()
        self.hbox2 = QtWidgets.QHBoxLayout()
        self.hbox3 = QtWidgets.QHBoxLayout()
        self.hbox4 = QtWidgets.QHBoxLayout()
        self.vbox.addLayout(self.hbox1)
        self.vbox.addLayout(self.hbox2)
        self.vbox.addLayout(self.hbox3)
        self.vbox.addLayout(self.hbox4)
Ejemplo n.º 13
0
class PlotGenerator(QFrame):

    def __init__(self, plot_path, plot_config_path):
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.plot_figure = PlotFigure()
        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        size = QSize(297*2, 210*2) # A4 aspectratio
        self.canvas.setMaximumSize(size)
        self.canvas.setMinimumSize(size)
        self.setMaximumSize(size)
        self.setMinimumSize(size)

        self.popup = Popup(self)
        self.plot_config_loader = PlotSettingsLoader()
        self.plot_settings = PlotSettings()
        self.plot_settings.setPlotPath(plot_path)
        self.plot_settings.setPlotConfigPath(plot_config_path)
        self.connect(self.popup, SIGNAL('updateProgress(int)'), self.updateProgress)


        self.plot_context_data_fetcher = PlotContextDataFetcher()
        self.plot_context_data_fetcher.initialize(self.plot_context_data_fetcher.getModel())
        self.plot_data_fetcher = PlotDataFetcher()
        self.plot_data_fetcher.initialize(self.plot_data_fetcher.getModel())

    def updateProgress(self, progress = 1):
        value = self.popup.progress_bar.value()
        self.popup.progress_bar.setValue(value + progress)

    def saveAll(self):
        self.popup.show()

        context_data = self.plot_context_data_fetcher.getFromModel()

        save_list = []
        count = 0
        for parameter in context_data.parameters:
            pt = parameter.type

            if pt == SummaryModel.TYPE or pt == KeywordModel.TYPE or pt == enums.obs_impl_type.FIELD_OBS:
                save_list.append(parameter)
                parameter.setUserData({'state' : enums.ert_state_enum.FORECAST})

                if pt == KeywordModel.TYPE:
                    choices = context_data.key_index_list[parameter.name]
                    parameter.getUserData()['key_index_choices'] = choices
                    count += len(choices)
                else:
                    count += 1


        self.popup.progress_bar.setMaximum(count)

        for parameter in save_list:
            if parameter.type == KeywordModel.TYPE:
                for choice in parameter.getUserData()['key_index_choices']:
                    self.plot_data_fetcher.setParameter(parameter, context_data)
                    parameter.getUserData()['key_index'] = choice # because setParameter overwrites this value
                    self.plot_data_fetcher.fetchContent()
                    self.savePlot(self.plot_data_fetcher.data)
            else:
                self.plot_data_fetcher.setParameter(parameter, context_data)
                self.plot_data_fetcher.fetchContent()
                self.savePlot(self.plot_data_fetcher.data)

        self.popup.ok_button.setEnabled(True)

    def save(self, plot_data):
        self.popup.show()

        self.popup.progress_bar.setMaximum(1)

        self.savePlot(plot_data)
        self.popup.ok_button.setEnabled(True)


    def savePlot(self, plot_data):
        generated_plot = self.generatePlot(plot_data)
        if generated_plot:
            self.savePlotToFile(plot_data.getSaveName())
        self.popup.emit(SIGNAL('updateProgress(int)'), 1)

    def generatePlot(self, plot_data):
        name = plot_data.getSaveName()
        load_success = self.plot_config_loader.load(name, self.plot_settings)

        if load_success:
            self.plot_figure.drawPlot(plot_data, self.plot_settings)
            self.canvas.draw()

        return load_success

    def savePlotToFile(self, filename):
        """Save the plot visible in the figure."""
        plot_path = self.plot_settings.getPlotPath()
        if not os.path.exists(plot_path):
            os.makedirs(plot_path)

        path = plot_path + "/" + filename
        self.plot_figure.getFigure().savefig(path + ".png", dpi=400, format="png")
        self.plot_figure.getFigure().savefig(path + ".pdf", dpi=400, format="pdf")
Ejemplo n.º 14
0
class PlotView(QFrame):
    """PlotView presents a matplotlib canvas with interaction possibilities. (picking and tooltip)"""
    def __init__(self):
        """Create a PlotView instance"""
        QFrame.__init__(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        # setup some default data values
        self.data = PlotData()
        self.data.x_data_type = "number"
        self.data.setValid(False)

        self.plot_figure = PlotFigure()
        self.plot_settings = PlotSettings()

        self.canvas = FigureCanvas(self.plot_figure.getFigure())
        self.canvas.setParent(self)
        self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.mouse_handler = MouseHandler(self)

    def toggleMember(self, line):
        gid = int(line.get_gid())
        if gid in self.plot_settings.getSelectedMembers():
            self.plot_settings.unselectMember(gid)
        else:
            self.plot_settings.selectMember(gid)

    @ert_gui.widgets.util.may_take_a_long_time
    def drawPlot(self):
        self.plot_figure.drawPlot(self.data, self.plot_settings)
        self.canvas.draw()

    def resizeEvent(self, event):
        QFrame.resizeEvent(self, event)
        self.canvas.resize(event.size().width(), event.size().height())

    def loadSettings(self, name):
        if self.data.isValid():
            plot_config_loader = PlotSettingsLoader()
            if not plot_config_loader.load(name, self.plot_settings):
                self.drawPlot()

    def saveSettings(self):
        if self.data.isValid():
            plot_config_saver = PlotSettingsSaver()
            plot_config_saver.save(self.data.getSaveName(), self.plot_settings)

    def setData(self, data):
        self.saveSettings()

        self.data = data

        self.loadSettings(self.data.getSaveName())

    def setXZoomFactors(self, xminf, xmaxf):
        self.plot_settings.setMinXZoom(xminf)
        self.plot_settings.setMaxXZoom(xmaxf)

    def setYZoomFactors(self, yminf, ymaxf):
        self.plot_settings.setMinYZoom(yminf)
        self.plot_settings.setMaxYZoom(ymaxf)

    def save(self):
        self.saveSettings()

        plot_generator = PlotGenerator(self.plot_settings.getPlotPath(),
                                       self.plot_settings.getPlotConfigPath())
        plot_generator.save(self.data)

    def saveAll(self):
        self.saveSettings()

        plot_generator = PlotGenerator(self.plot_settings.getPlotPath(),
                                       self.plot_settings.getPlotConfigPath())
        plot_generator.saveAll()

    def copyPlotSettings(self):
        plot_config_loader = PlotSettingsLoader()
        plot_config_loader.copy(self.plot_settings)

    def setPlotPath(self, plot_path):
        self.plot_settings.setPlotPath(plot_path)

    def setPlotConfigPath(self, path):
        self.plot_settings.setPlotConfigPath(path)

    def _selectedMemberIdentifier(self, artist):
        return artist.get_gid() in self.plot_settings.getSelectedMembers()

    def clearSelection(self):
        selected_lines = self.plot_figure.fig.findobj(
            self._selectedMemberIdentifier)
        for line in selected_lines:
            self.plot_settings.unselectMember(line.get_gid())

    def displayToolTip(self, event):
        if not self.data is None and not event.xdata is None and not event.ydata is None:
            if self.data.getXDataType() == "time":
                date = matplotlib.dates.num2date(event.xdata)
                self.setToolTip("x: %s y: %04f" %
                                (date.strftime("%d/%m-%Y"), event.ydata))
            else:
                self.setToolTip("x: %04f y: %04f" % (event.xdata, event.ydata))
        else:
            self.setToolTip("")

    def annotate(self, label, x, y, xt=None, yt=None):
        self.plot_settings.addAnnotation(label, x, y, xt, yt)

    def removeAnnotation(self, annotation_artist):
        annotations = self.plot_settings.getAnnotations()
        for annotation in annotations:
            if annotation.getUserData() == annotation_artist:
                self.plot_settings.removeAnnotation(annotation)

    def moveAnnotation(self, annotation_artist, xt, yt):
        annotations = self.plot_settings.getAnnotations()
        for annotation in annotations:
            if annotation.getUserData() == annotation_artist:
                annotation.xt = xt
                annotation.yt = yt

        annotation_artist.xytext = (xt, yt)

    def draw(self):
        self.canvas.draw()

    def setMinYLimit(self, value):
        self.plot_settings.setMinYLimit(value)

    def setMaxYLimit(self, value):
        self.plot_settings.setMaxYLimit(value)

    def setMinXLimit(self, value):
        self.plot_settings.setMinXLimit(value)

    def setMaxXLimit(self, value):
        self.plot_settings.setMaxXLimit(value)

    def getPlotConfigList(self):
        return self.plot_settings.getPlotConfigList()