Example #1
0
class MPL_Widget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.canvas = MyMplCanvas()
        #self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        #self.toolbar.hide()
        self.hbox = QtGui.QHBoxLayout()
        #self.hbox.addWidget(self.toolbar)
        self.hbox.addWidget(self.canvas)
        self.setLayout(self.hbox)
        ##########################
        self.hZoom = QtGui.QAction("Zoom", self)
        self.hZoom.setShortcut("Ctrl+Z")
        self.addAction(self.hZoom)
        QtCore.QObject.connect(self.hZoom, QtCore.SIGNAL("triggered()"),
                               self.ZoomToggle)

        self.actionAutoScale = QtGui.QAction("AutoScale",
                                             self)  #self.MainWindow)
        self.actionAutoScale.setShortcut("Ctrl+A")
        self.addAction(self.actionAutoScale)
        QtCore.QObject.connect(self.actionAutoScale,
                               QtCore.SIGNAL("triggered()"),
                               self.autoscale_plot)

    def ZoomToggle(self):
        self.toolbar.zoom()

    def autoscale_plot(self):
        self.toolbar.home()
Example #2
0
    def __init__(self, canvas, frame, name=None):
        """ Create a new toolbar object

        Parameters
        ----------
        data_collection : DataCollection instance
         The data collection that this toolbar is meant to edit.
         The toolbar looks to this collection for the available subsets
         to manipulate.
        canvas : Maptloblib canvas instance
         The drawing canvas to interact with
        frame : QWidget
         The QT frame that the canvas is embedded within.
        """
        self.buttons = {}
        self.__active = None
        self.basedir = None
        NavigationToolbar2QT.__init__(self, canvas, frame)
        if name is not None:
            self.setWindowTitle(name)
        self.setIconSize(QtCore.QSize(25, 25))
        self.layout().setSpacing(1)
        self.setFocusPolicy(Qt.StrongFocus)
        self._idKey = None

        # pyside is prone to segfaults if slots hold the only
        # reference to a signal, so we hold an extra reference
        # see https://bugreports.qt-project.org/browse/PYSIDE-88
        self.__signals = []
Example #3
0
    def __init__(self, canvas, frame, name=None):
        """ Create a new toolbar object

        Parameters
        ----------
        data_collection : DataCollection instance
         The data collection that this toolbar is meant to edit.
         The toolbar looks to this collection for the available subsets
         to manipulate.
        canvas : Maptloblib canvas instance
         The drawing canvas to interact with
        frame : QWidget
         The QT frame that the canvas is embedded within.
        """
        self.buttons = {}
        self.__active = None
        self.basedir = None
        NavigationToolbar2QT.__init__(self, canvas, frame)
        if name is not None:
            self.setWindowTitle(name)
        self.setIconSize(QtCore.QSize(25, 25))
        self.layout().setSpacing(1)
        self.setFocusPolicy(Qt.StrongFocus)
        self._idKey = None

        # pyside is prone to segfaults if slots hold the only
        # reference to a signal, so we hold an extra reference
        # see https://bugreports.qt-project.org/browse/PYSIDE-88
        self.__signals = []
    def __init__(self):
        Qt.QMainWindow.__init__(self, None)
#                            "application main window",
#                            Qt.WType_TopLevel | Qt.WDestructiveClose)

        self.file_menu = Qt.QMenu('&File',self)
        self.file_menu.addAction('&Quit', self.fileQuit, Qt.Qt.CTRL + Qt.Qt.Key_Q)
        self.menuBar().addMenu(self.file_menu)

        self.help_menu = Qt.QMenu('&Help', self)
        self.menuBar().addSeparator()
        self.menuBar().addMenu(self.help_menu)

        self.help_menu.addAction('&About', self.about)

        self.main_widget = Qt.QWidget(self)

        l = Qt.QVBoxLayout(self.main_widget)
        sc = MyPylabPlotter(self.main_widget, dpi=100)
        toolbar = NavigationToolbar(sc, self.main_widget)
        toolbar.setSizePolicy(Qt.QSizePolicy.Expanding,Qt.QSizePolicy.Fixed)
        l.addWidget(sc)
        l.addWidget(toolbar)

        self.main_widget.setFocus()
        self.setCentralWidget(self.main_widget)

# Produce a plot that is contained in MyPylabPlotter
        sc.demo_pythonic_matplotlib()
# Produce a plot that is separate from MyPylabPlotter
        sc.demo_pylab_figure()
Example #5
0
        def __init__(self):
            Qt.QMainWindow.__init__(self, None)
            #                            "application main window",
            #                            Qt.WType_TopLevel | Qt.WDestructiveClose)

            self.file_menu = Qt.QMenu("&File", self)
            self.file_menu.addAction("&Quit", self.fileQuit, Qt.Qt.CTRL + Qt.Qt.Key_Q)
            self.menuBar().addMenu(self.file_menu)

            self.help_menu = Qt.QMenu("&Help", self)
            self.menuBar().addSeparator()
            self.menuBar().addMenu(self.help_menu)

            self.help_menu.addAction("&About", self.about)

            self.main_widget = Qt.QWidget(self)

            l = Qt.QVBoxLayout(self.main_widget)
            sc = MyPylabPlotter(self.main_widget, dpi=100)
            toolbar = NavigationToolbar(sc, self.main_widget)
            toolbar.setSizePolicy(Qt.QSizePolicy.Expanding, Qt.QSizePolicy.Fixed)
            l.addWidget(sc)
            l.addWidget(toolbar)

            self.main_widget.setFocus()
            self.setCentralWidget(self.main_widget)

            # Produce a plot that is contained in MyPylabPlotter
            sc.demo_pythonic_matplotlib()
            # Produce a plot that is separate from MyPylabPlotter
            sc.demo_pylab_figure()
class MPL_Widget(QtGui.QWidget):
    def __init__(self, parent = None):
        QtGui.QWidget.__init__(self, parent)
        self.canvas = MyMplCanvas()
        #self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        #self.toolbar.hide()
        self.hbox = QtGui.QHBoxLayout()
        #self.hbox.addWidget(self.toolbar)
        self.hbox.addWidget(self.canvas)
        self.setLayout(self.hbox)
        ##########################
        self.hZoom = QtGui.QAction("Zoom",  self)
        self.hZoom.setShortcut("Ctrl+Z")
        self.addAction(self.hZoom)
        QtCore.QObject.connect(self.hZoom,QtCore.SIGNAL("triggered()"), self.ZoomToggle)

        self.actionAutoScale = QtGui.QAction("AutoScale",  self)#self.MainWindow)
        self.actionAutoScale.setShortcut("Ctrl+A")
        self.addAction(self.actionAutoScale)
        QtCore.QObject.connect(self.actionAutoScale,QtCore.SIGNAL("triggered()"), self.autoscale_plot)

    def ZoomToggle(self):
        self.toolbar.zoom()

    def autoscale_plot(self):
        self.toolbar.home()
Example #7
0
 def _init_toolbar(self):
     NavigationToolbar2QT._init_toolbar(self) 
    
     # adding a new icon
     icon=QtGui.QIcon()
     icon.addPixmap(QtGui.QPixmap(":/MPL Toolbar/export_ascii.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
     a=self.addAction(icon, "Export", self.export_ascii)
     a.setToolTip('Export the plot into ASCII file')
Example #8
0
class MPL_Widget(QWidget):
    def __init__(self, parent = None):
        QWidget.__init__(self, parent)
        self.canvas = MyMplCanvas()
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)    #no toolbar
        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.canvas)
        self.vbox.addWidget(self.toolbar)
        self.toolbar.hide()
        self.setLayout(self.vbox)
Example #9
0
    def __init__(self , canvas , parent , direction = 'h' ) :
        #NavigationToolbar.__init__(self,parent,canvas)
        #self.layout = QVBoxLayout( self )
        self.canvas = canvas
        QtGui.QWidget.__init__( self, parent )

        if direction=='h' :    self.layout = QtGui.QHBoxLayout( self )
        else : self.layout = QtGui.QVBoxLayout( self )
        self.layout.setMargin( 2 )
        self.layout.setSpacing( 0 )
        NavigationToolbar.__init__( self, canvas, parent ) 
Example #10
0
    def __init__(self, canvas, parent, coordinates=True):
        """
        Constructor of NavToolBar

        :param canvas: the matplotlib canvas
        :type canvas: matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
        :param parent: the parent QWidget
        :type parent: PyQt4.QtGui.QWidget
        :param coordinates: boolean coordinates
        :type coordinates: bool
        """
        NavigationToolbar2QT.__init__(self, canvas, parent, coordinates)
        self.setIconSize(QSize(16, 16))
Example #11
0
    def __init__(self, parent, canvas, direction = 'h') :

        self.canvas = canvas
        QtGui.QWidget.__init__(self, parent)

        if direction=='h' :
            self.layout = QtGui.QHBoxLayout(self)
        else:
            self.layout = QtGui.QVBoxLayout(self)

        self.layout.setMargin(2)
        self.layout.setSpacing(0)

        NavigationToolbar.__init__(self, parent, canvas)
Example #12
0
    def edit_parameters(self):
        theresult = NavigationToolbar2QT.edit_parameters(self)

        # we update the legend ourselves
        self.updateLegend()

        return theresult
    def Plot_Function(self):
        '''
            Clears Matplotlib Widget Canvas
            
            Adds 3 subplots
            
            plots Difference Data
            
            sharex - shares x axis between subplots
            '''
        #self.legend.remove()

        #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
        self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
        self.navi_toolbar.clear()

        #Adds Buttons
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'),
                                        'Home', self.navi_toolbar.home)
        #a.setToolTip('returns axes to original position')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'),
                                        'Pan', self.navi_toolbar.pan)
        a.setToolTip('Pan axes with left mouse, zoom with right')
        a = self.navi_toolbar.addAction(
            self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
            self.navi_toolbar.zoom)
        a.setToolTip('Zoom to Rectangle')
        a = self.navi_toolbar.addAction(
            self.navi_toolbar._icon('filesave.png'), 'Save',
            self.navi_toolbar.save_figure)
        a.setToolTip('Save the figure')

        self.toolbar_grid.addWidget(self.navi_toolbar)

        self.top_xval = self.top_data[self.top_data.dtype.names[
            self.top_xcombo.currentIndex()]]
        self.top_yval = self.top_data[self.top_data.dtype.names[
            self.top_ycombo.currentIndex()]]
        self.yval = self.yval - np.median(self.yval)

        x1 = np.linspace(0.0, 5.0)
        y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
        y2 = np.cos(3 * np.pi * x1) * np.exp(-x1)
        y3 = np.cos(4 * np.pi * x1) * np.exp(-x1)
        self.mpl.canvas.fig.clear()

        self.plot1 = self.mpl.canvas.fig.add_subplot(3, 1, 1)
        #self.plot1.plot(self.top_xval,self.top_yval)

        self.plot2 = self.mpl.canvas.fig.add_subplot(3,
                                                     1,
                                                     2,
                                                     sharex=self.plot1)
        self.plot2.plot(x1, y2)

        self.plot3 = self.mpl.canvas.fig.add_subplot(3,
                                                     1,
                                                     3,
                                                     sharex=self.plot1)
        self.plot3.plot(x1, y3)
Example #14
0
class MPLCanvasWidget(QWidget):
    def __init__(self, fig):
        QWidget.__init__(self)
        self._fig = fig
        self._layout = QVBoxLayout()
        self._canvas = FigureCanvas(self._fig)
        self._toolbar = NavigationToolbar(self._canvas, self)
        self._layout.addWidget(self._toolbar)
        self._layout.addWidget(self._canvas)
        self.setLayout(self._layout)

        # resize the figure
        # dpi = self._fig.get_dpi()
        # width = int(self._fig.get_figwidth() * dpi) + margins[0] + margins[2]
        # height = int(self._fig.get_figheight() * dpi) + margins[1] + margins[3]
        # self._canvas.resize(width, height)
        # self._canvas.resize(self._canvas.sizeHint())
        # this is a hack to keep the figure close to the right size (pixels)
        # everything above this code does not work
        size = self.sizeHint()
        margins = self._layout.getContentsMargins()
        width = size.width() + margins[0]
        height = size.height() + self._toolbar.sizeHint().height()
        # print width, height
        self.resize(width, height)

    def closeEvent(self, QCloseEvent):
        super(MPLCanvasWidget, self).closeEvent(QCloseEvent)
        plt.close(fig=self._fig)

    def get_fig(self):
        return self._fig
Example #15
0
    def show_pylab_plot(self, store_rec=True):
        """ process incoming data and attributes into the
        appropriate type of plot """

        # if we are single stepping through requests, Oleg may reset the
        # cache, so check for a non-data record situation
        if store_rec and isinstance(self._rec, bool):
            return

        pylab_record = self._rec.plotdefs
        if not self._pylab_plotter is None:
            #     self._pylab_plotter.reparent(Qt.QWidget(), 0, Qt.QPoint())
            self._pylab_plotter.setParent(Qt.QWidget())
            self._pylab_plotter = None
        if not self._toolbar is None:
            #     self._toolbar.reparent(Qt.QWidget(), 0, Qt.QPoint())
            self._toolbar.setParent(Qt.QWidget())
            self._toolbar = None
        if self._pylab_plotter is None:
            self._pylab_plotter = MyPylabPlotter(parent=self.layout_parent)
            self.layout.addWidget(self._pylab_plotter, 1, 0)
            self._pylab_plotter.show()
        if self._toolbar is None:
            self._toolbar = NavigationToolbar(self._pylab_plotter, self.layout_parent)
            self._toolbar.setSizePolicy(Qt.QSizePolicy.Expanding, Qt.QSizePolicy.Fixed)
            self.layout.addWidget(self._toolbar, 0, 0)
            self._toolbar.show()
        self._pylab_plotter.make_plot(pylab_record)
Example #16
0
    def __init__(self, parent=None):
        # initialization of the superclass
        super(ArchaeoPYMainWindow, self).__init__(parent)
        # setup the GUI --> function generated by pyuic4
        self.setupUi(self)
        #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
        self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
        self.navi_toolbar.clear()

        #Adds Buttons
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'),
                                        'Home', self.navi_toolbar.home)
        #a.setToolTip('returns axes to original position')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'),
                                        'Pan', self.navi_toolbar.pan)
        a.setToolTip('Pan axes with left mouse, zoom with right')
        a = self.navi_toolbar.addAction(
            self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
            self.navi_toolbar.zoom)
        a.setToolTip('Zoom to Rectangle')
        a = self.navi_toolbar.addAction(
            self.navi_toolbar._icon('filesave.png'), 'Save',
            self.navi_toolbar.save_figure)
        a.setToolTip('Save the figure')

        #Button_layout is a QT desginer Grid Layout.
        self.toolbar_grid.addWidget(self.navi_toolbar)
        self.Button_Definitions()
        self.plot_options()
Example #17
0
    def __init__(self, parent=None):
        # initialization of the superclass
        super(ArchaeoPYMainWindow, self).__init__(parent)
        # setup the GUI --> function generated by pyuic4
        self.setupUi(self)
        # Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
        self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
        self.navi_toolbar.clear()

        # Adds Buttons
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("home.png"), "Home", self.navi_toolbar.home)
        # a.setToolTip('returns axes to original position')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("move.png"), "Pan", self.navi_toolbar.pan)
        a.setToolTip("Pan axes with left mouse, zoom with right")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("zoom_to_rect.png"), "Zoom", self.navi_toolbar.zoom)
        a.setToolTip("Zoom to Rectangle")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("filesave.png"), "Save", self.navi_toolbar.save_figure)
        a.setToolTip("Save the figure")

        QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard)

        # self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label')

        # Button_layout is a QT desginer Grid Layout.
        self.toolbar_grid.addWidget(self.navi_toolbar)
        self.button_grid()
Example #18
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.canvas = SetPlot()
        self.vbl = QtGui.QVBoxLayout()
        self.ntb = NavigationToolbar(self.canvas, parent)
        self.ntb.hide()
        self.vbl.addWidget(self.ntb)
        self.vbl.addWidget(self.canvas)
        self.setLayout(self.vbl)

        self.flag_Zero = True
        self.flag_onlinedata = False
        self.flag_online = False
        self.flag_offline = False

        self.dataX_online = []
        self.dataY_online = []
        self.dataX_offline = []
        self.dataY_offline = []
        self.offlinedata = []
        self.onlinedata = []
        self.count_online = 0
        self.count_offline = 0
        self.count_onlinedata = 0
        self.initDataGenerator()
     def __init__(self, parent = None):
         # initialization of the superclass
         super(ArchaeoPYMainWindow, self).__init__(parent)
         # setup the GUI --> function generated by pyuic4
         self.setupUi(self)
         #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
         self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
         self.navi_toolbar.clear()
 
     #Adds Buttons
         a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home',
                                         self.navi_toolbar.home)
         #a.setToolTip('returns axes to original position')
         a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan',
                                         self.navi_toolbar.pan)
         a.setToolTip('Pan axes with left mouse, zoom with right')
         a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
                                         self.navi_toolbar.zoom)
         a.setToolTip('Zoom to Rectangle')
         a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save',
                            self.navi_toolbar.save_figure)
         a.setToolTip('Save the figure')
 
         #Button_layout is a QT desginer Grid Layout.
         self.toolbar_grid.addWidget(self.navi_toolbar)
         self.Button_Definitions()
         self.plot_options()
Example #20
0
    def __init__(self,parent=None):
        QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
    
        self.atten = -1
        self.ui.atten.setValue(self.atten)  
        self.resnum = 0
        self.indx=0
        
        QObject.connect(self.ui.open_browse, SIGNAL("clicked()"), self.open_dialog)
        QObject.connect(self.ui.save_browse, SIGNAL("clicked()"), self.save_dialog)
        QObject.connect(self.ui.atten, SIGNAL("valueChanged(int)"), self.setnewatten)
        QObject.connect(self.ui.savevalues, SIGNAL("clicked()"), self.savevalues)
        QObject.connect(self.ui.jumptores, SIGNAL("clicked()"), self.jumptores)

        self.widesweep=None
        try:
            path='/home/data/MEC/20180517/'
            ws_FN = 'HypatiaFL5a_digWS_r222.txt'
            ws_freqs_all_FN = 'HypatiaFL5a_digWS_r222-freqs-all.txt'
            ws_freqs_good_FN = 'HypatiaFL5a_digWS_r222-freqs-good.txt'
            self.widesweep=numpy.loadtxt(path+ws_FN)  #freq, I, Q
            self.widesweep_goodFreqs = numpy.loadtxt(path+ws_freqs_good_FN ,usecols=[2])
            self.widesweep_allResIDs,self.widesweep_allFreqs = numpy.loadtxt(path+ws_freqs_all_FN,usecols=[0,2],unpack=True)
        except IOError:
            pass

        self.navi_toolbar = NavigationToolbar(self.ui.plot_3.canvas, self)
        self.ui.plot_3.canvas.setFocusPolicy( Qt.ClickFocus )
        cid=self.ui.plot_3.canvas.mpl_connect('key_press_event', self.zoom_plot_3)
Example #21
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.canvas = MyMplCanvas()
        #self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        self.toolbar.hide()
        self.hbox = QtGui.QHBoxLayout()
        #self.hbox.addWidget(self.toolbar)
        self.hbox.addWidget(self.canvas)
        self.setLayout(self.hbox)
        ##########################
        self.hZoom = QtGui.QAction("Zoom", self)
        self.hZoom.setShortcut("Ctrl+Z")
        self.addAction(self.hZoom)
        QtCore.QObject.connect(self.hZoom, QtCore.SIGNAL("triggered()"),
                               self.ZoomToggle)

        self.actionAutoScale = QtGui.QAction("AutoScale",
                                             self)  #self.MainWindow)
        self.actionAutoScale.setShortcut("Ctrl+A")
        self.addAction(self.actionAutoScale)
        QtCore.QObject.connect(self.actionAutoScale,
                               QtCore.SIGNAL("triggered()"),
                               self.autoscale_plot)

        self.installEventFilter(EventFilter(self))

        ###########SAVING FIGURE TO CLIPBOARD##########
        self.cb = None  #will be used for the clipboard
        self.tempPath = getHomeDir()
        self.tempPath = os.path.join(self.tempPath, 'tempMPL.png')
  def show_pylab_plot(self, store_rec=True):
    """ process incoming data and attributes into the
        appropriate type of plot """

    # if we are single stepping through requests, Oleg may reset the
    # cache, so check for a non-data record situation
    if store_rec and isinstance(self._rec, bool):
      return

    pylab_record = self._rec.plotdefs
    if not self._pylab_plotter is None:
#     self._pylab_plotter.reparent(Qt.QWidget(), 0, Qt.QPoint())
      self._pylab_plotter.setParent(Qt.QWidget())
      self._pylab_plotter  = None
    if not self._toolbar is None:
#     self._toolbar.reparent(Qt.QWidget(), 0, Qt.QPoint())
      self._toolbar.setParent(Qt.QWidget())
      self._toolbar = None
    if self._pylab_plotter is None:
      self._pylab_plotter = MyPylabPlotter(parent=self.layout_parent)
      self.layout.addWidget(self._pylab_plotter,1,0)
      self._pylab_plotter.show()
    if self._toolbar is None:
      self._toolbar = NavigationToolbar(self._pylab_plotter, self.layout_parent)
      self._toolbar.setSizePolicy(Qt.QSizePolicy.Expanding,Qt.QSizePolicy.Fixed)
      self.layout.addWidget(self._toolbar,0,0)
      self._toolbar.show()
    self._pylab_plotter.make_plot(pylab_record)
Example #23
0
 def initializeMatplotlib(self):
     self.figure = mpl.figure()
     self.oldParent = self.figure.canvas.parent()
     self.figure.canvas.setParent(self)
     self.canvasFrame.layout().addWidget(self.figure.canvas)
     self.toolbar = NavigationToolbar2QT(self.figure.canvas, self)
     self.addToolBar(self.toolbar)
Example #24
0
    def __init__(self, parent = None):
        QtGui.QWidget.__init__(self, parent)
        self.canvas = MyMplCanvas()
        #self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        self.toolbar.hide()
        self.hbox = QtGui.QHBoxLayout()
        #self.hbox.addWidget(self.toolbar)
        self.hbox.addWidget(self.canvas)
        self.setLayout(self.hbox)
        ##########################
        self.hZoom = QtGui.QAction("Zoom",  self)
        self.hZoom.setShortcut("Ctrl+Z")
        self.addAction(self.hZoom)
        QtCore.QObject.connect(self.hZoom,QtCore.SIGNAL("triggered()"), self.ZoomToggle)

        self.actionAutoScale = QtGui.QAction("AutoScale",  self)#self.MainWindow)
        self.actionAutoScale.setShortcut("Ctrl+A")
        self.addAction(self.actionAutoScale)
        QtCore.QObject.connect(self.actionAutoScale,QtCore.SIGNAL("triggered()"), self.autoscale_plot)


        self.installEventFilter(EventFilter(self))

        ###########SAVING FIGURE TO CLIPBOARD##########
        self.cb = None #will be used for the clipboard
        self.tempPath = getHomeDir()
        self.tempPath = os.path.join(self.tempPath,'tempMPL.png')
Example #25
0
class PlotWidget(QtGui.QWidget):
    """This class represents the plot view for plotting graphs.

    :returns: an instance of *PlotWidget*
    """

    def __init__(self,):
        QtGui.QWidget.__init__(self)
        self.figure = Figure(facecolor=(1, 1, 1), tight_layout=True)

        self.ax = self.figure.add_subplot(111)

        # Canvas
        self.canvas = FigureCanvas(self.figure)
        self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Expanding)
        self.canvas.updateGeometry()

        # Navigation
        self.navi_toolbar = NavigationToolbar(self.canvas, self)
        self.navi_toolbar.setOrientation(QtCore.Qt.Vertical)
        # Fixed with, otherwise navigation bar resize arbitrary
        self.navi_toolbar.setFixedWidth(40)

        self.vbl = QtGui.QHBoxLayout()
        self.vbl.addWidget(self.navi_toolbar)
        self.vbl.addWidget(self.canvas)
        self.setLayout(self.vbl)

    def plot(self, x_data_1, y_data_1, x_data_2, y_data_2):
        """Plot given data on *PlotWidget*.

        :param x_data_1: X-axis data for plot 1
        :type x_data_1: array_like
        :param y_data_1: Y-axis data for plot 1
        :type y_data_1: array_like
        :param x_data_2: X-axis data for plot 2
        :type x_data_2: array_like
        :param y_data_2: Y-axis data for plot 2
        :type y_data_2: array_like
        """
        self.ax.clear()
        self.ax.grid(True)
        self.ax.plot(x_data_1, y_data_1, 'b^', label='Input Data')
        self.ax.plot(x_data_2, y_data_2, 'b-', label='Fitted Data')
        self.ax.legend()
        self.canvas.draw()
Example #26
0
class PlotWidget(QtGui.QWidget):
    """This class represents the plot view for plotting graphs.

    :returns: an instance of *PlotWidget*
    """
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.figure = Figure(facecolor=(1, 1, 1), tight_layout=True)

        self.ax = self.figure.add_subplot(111)

        # Canvas
        self.canvas = FigureCanvas(self.figure)
        self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Expanding)
        self.canvas.updateGeometry()

        # Navigation
        self.navi_toolbar = NavigationToolbar(self.canvas, self)
        self.navi_toolbar.setOrientation(QtCore.Qt.Vertical)
        # Fixed with, otherwise navigation bar resize arbitrary
        self.navi_toolbar.setFixedWidth(40)

        self.vbl = QtGui.QHBoxLayout()
        self.vbl.addWidget(self.navi_toolbar)
        self.vbl.addWidget(self.canvas)
        self.setLayout(self.vbl)

    def plot(self, x_data_1, y_data_1, x_data_2, y_data_2):
        """Plot given data on *PlotWidget*.

        :param x_data_1: X-axis data for plot 1
        :type x_data_1: array_like
        :param y_data_1: Y-axis data for plot 1
        :type y_data_1: array_like
        :param x_data_2: X-axis data for plot 2
        :type x_data_2: array_like
        :param y_data_2: Y-axis data for plot 2
        :type y_data_2: array_like
        """
        self.ax.clear()
        self.ax.grid(True)
        self.ax.plot(x_data_1, y_data_1, 'b^', label='Input Data')
        self.ax.plot(x_data_2, y_data_2, 'b-', label='Fitted Data')
        self.ax.legend()
        self.canvas.draw()
Example #27
0
class MatplotlibWidget(QtGui.QWidget):

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.frame = QWidget()
        self.canvas = MplCanvas()
        self.canvas.setParent(self.frame)
        self.mpltoolbar = Navigationtoolbar(self.canvas, self.frame)
        self.vbl = QtGui.QVBoxLayout()
        self.vbl.addWidget(self.canvas)
        self.vbl.addWidget(self.mpltoolbar)
        self.setLayout(self.vbl)

        self.mpltoolbar.toggleViewAction()

    def setTitle(self, text):
        """
        Sets the figure title
        """
        self.canvas.setTitle(text)

    def get_axis(self):
        return self.canvas.ax

    def get_figure(self):
        return self.canvas.fig

    def clear(self, force=False):
        if force:
            self.canvas.fig.clear()
            self.canvas.ax = self.canvas.fig.add_subplot(111)
            # self.canvas.ax.clear()
            # self.canvas = MplCanvas()
        else:
            self.canvas.ax.clear()

    def redraw(self):
        self.canvas.ax.figure.canvas.draw()

    def plot(self, x, y, title='', xlabel='', ylabel=''):
        self.setTitle(title)
        self.canvas.ax.plot(x, y)

        self.redraw()
Example #28
0
class MatplotlibWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.frame = QWidget()
        self.canvas = MplCanvas()
        self.canvas.setParent(self.frame)
        self.mpltoolbar = Navigationtoolbar(self.canvas, self.frame)
        self.vbl = QtGui.QVBoxLayout()
        self.vbl.addWidget(self.canvas)
        self.vbl.addWidget(self.mpltoolbar)
        self.setLayout(self.vbl)

        self.mpltoolbar.toggleViewAction()

    def setTitle(self, text):
        """
        Sets the figure title
        """
        self.canvas.setTitle(text)

    def get_axis(self):
        return self.canvas.ax

    def get_figure(self):
        return self.canvas.fig

    def clear(self, force=False):
        if force:
            self.canvas.fig.clear()
            self.canvas.ax = self.canvas.fig.add_subplot(111)
            # self.canvas.ax.clear()
            # self.canvas = MplCanvas()
        else:
            self.canvas.ax.clear()

    def redraw(self):
        self.canvas.ax.figure.canvas.draw()

    def plot(self, x, y, title='', xlabel='', ylabel=''):
        self.setTitle(title)
        self.canvas.ax.plot(x, y)

        self.redraw()
Example #29
0
    def __init__(self,
                 parent=None,
                 enableAutoScale=True,
                 enableCSV=False,
                 enableEdit=True,
                 doublePlot=False,
                 layoutDir='h'):
        QtGui.QWidget.__init__(self, parent)
        if doublePlot:
            self.canvas = DoubleMyMplCanvas()
        else:
            self.canvas = MyMplCanvas()
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        #        self.toolbar.hide()
        self.installEventFilter(EventFilter(self))

        if layoutDir == 'v':
            self.toolbar.setOrientation(QtCore.Qt.Vertical)
            self.layout = QtGui.QHBoxLayout()

        elif layoutDir == 'h':
            self.layout = QtGui.QVBoxLayout()
#            self.layout.addWidget(self.canvas)
#            self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.canvas)
        self.setLayout(self.layout)

        ##########################

        self.dataLabels = None

        ###########SAVING FIGURE TO CLIPBOARD##########
        self.cb = None  #will be used for the clipboard
        self.tempPath = getHomeDir()
        self.tempPath = os.path.join(self.tempPath, 'tempMPL.png')

        if enableEdit:
            self.enableEdit()

        self.lineDict = None
        self.addLegend = False

        self.x = None  #used for picker
        self.y = None

        #######SAVING FIGURE DATA############################
        if enableCSV:
            self.enableCSV()

        ########### HELPER FUNCTIONS #########################
        self.clearPlotAction = QtGui.QAction("Clear Plot", self)
        self.addAction(self.clearPlotAction)
        QtCore.QObject.connect(self, QtCore.SIGNAL("triggered()"),
                               self.clearPlot)
Example #30
0
    def init_plots(self):
        """ Initialize plots used in plugin """
        self.plot_dock = QtGui.QDockWidget('TSTools Plots',
                                           self.iface.mainWindow())
        self.plot_dock.setObjectName('TSTools Plots')

        settings.plot_dirty = []
        for plot in plots.plots:
            self.plots.append(plot(self.iface))
            settings.plot_dirty.append(False)

        self.plot_tabs = QtGui.QTabWidget(self.plot_dock)

        @QtCore.pyqtSlot(int)
        def tab_changed(idx):
            """ Updates current tab index & re-plots if needed """
            settings.plot_current = idx
            if settings.plot_dirty[idx]:
                self.plots[idx].plot()
                settings.plot_dirty[idx] = False
        self.plot_tabs.currentChanged.connect(tab_changed)

        for plot in self.plots:
            widget = QtGui.QWidget()
            layout = QtGui.QHBoxLayout()
            nav = NavigationToolbar(plot, widget, coordinates=False)
            nav.setOrientation(QtCore.Qt.Vertical)

            nav.setSizePolicy(QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed)
            plot.setSizePolicy(QtGui.QSizePolicy.Preferred,
                               QtGui.QSizePolicy.Preferred)

            layout.addWidget(nav)
            layout.addWidget(plot)

            widget.setLayout(layout)
            self.plot_tabs.addTab(widget, plot.__str__())

        self.plot_dock.setWidget(self.plot_tabs)
        self.iface.addDockWidget(QtCore.Qt.BottomDockWidgetArea,
                                 self.plot_dock)
Example #31
0
    def init_plots(self):
        """ Initialize plots used in plugin """
        self.plot_dock = QtGui.QDockWidget('TSTools Plots',
                                           self.iface.mainWindow())
        self.plot_dock.setObjectName('TSTools Plots')

        settings.plot_dirty = []
        for plot in plots.plots:
            self.plots.append(plot(self.iface))
            settings.plot_dirty.append(False)

        self.plot_tabs = QtGui.QTabWidget(self.plot_dock)

        @QtCore.pyqtSlot(int)
        def tab_changed(idx):
            """ Updates current tab index & re-plots if needed """
            settings.plot_current = idx
            if settings.plot_dirty[idx]:
                self.plots[idx].plot()
                settings.plot_dirty[idx] = False

        self.plot_tabs.currentChanged.connect(tab_changed)

        for plot in self.plots:
            widget = QtGui.QWidget()
            layout = QtGui.QHBoxLayout()
            nav = NavigationToolbar(plot, widget, coordinates=False)
            nav.setOrientation(QtCore.Qt.Vertical)

            nav.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
            plot.setSizePolicy(QtGui.QSizePolicy.Preferred,
                               QtGui.QSizePolicy.Preferred)

            layout.addWidget(nav)
            layout.addWidget(plot)

            widget.setLayout(layout)
            self.plot_tabs.addTab(widget, plot.__str__())

        self.plot_dock.setWidget(self.plot_tabs)
        self.iface.addDockWidget(QtCore.Qt.BottomDockWidgetArea,
                                 self.plot_dock)
Example #32
0
    def __init__(self, figure_canvas, 
                 axes_canvas, parent=None):
        
        self.toolitems = (
            ('Home', 'Reset', 'home', 'home'),
            ('Pan', 'Pan', 'move', 'pan'),
            ('Zoom', 'Zoom', 'zoom_to_rect', 'zoom'),
            (None, None, None, None),
            ('Transect', 'make a transect', os.path.join(root_path,'icons','transect'),'transect_tool'),
            ('View', 'Switch view', os.path.join(root_path,'icons','switch'), 'switch_view'),
            ('Selector', 'Select node', os.path.join(root_path,'icons','select'), 'select_tool'),
            (None, None, None, None),
            ('Save', 'Save', 'filesave', 'save_figure')
            )

        #('Subplots', 'putamus parum claram', 'subplots', 'configure_subplots'),
        self.figure_canvas = figure_canvas
        self.axes_canvas = axes_canvas
    
        NavigationToolbar.__init__(self, figure_canvas, parent=parent)
Example #33
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.canvas = SetPlot()
        self.vbl = QtGui.QVBoxLayout()
        self.ntb = NavigationToolbar(self.canvas, parent)
        self.ntb.hide()
        self.vbl.addWidget(self.ntb)
        self.vbl.addWidget(self.canvas)
        self.setLayout(self.vbl)

        self.initDataGenerator()
Example #34
0
 def _create_canvas(self, parent):
     """ Create the MPL canvas. """
     # matplotlib commands to create a canvas
     frame = QtGui.QWidget()
     mpl_canvas = FigureCanvas(self.value)
     mpl_canvas.setParent(frame)
     mpl_toolbar = NavigationToolbar2QT(mpl_canvas, frame)
     vbox = QtGui.QVBoxLayout()
     vbox.addWidget(mpl_canvas)
     vbox.addWidget(mpl_toolbar)
     frame.setLayout(vbox)
     return frame
Example #35
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.frame = QWidget()
        self.canvas = MplCanvas()
        self.canvas.setParent(self.frame)
        self.mpltoolbar = Navigationtoolbar(self.canvas, self.frame)
        self.vbl = QtGui.QVBoxLayout()
        self.vbl.addWidget(self.canvas)
        self.vbl.addWidget(self.mpltoolbar)
        self.setLayout(self.vbl)

        self.mpltoolbar.toggleViewAction()
Example #36
0
    def __init__(self, canvas, frame, name=None):
        """ Create a new toolbar object

        Parameters
        ----------
        data_collection : DataCollection instance
         The data collection that this toolbar is meant to edit.
         The toolbar looks to this collection for the available subsets
         to manipulate.
        canvas : Maptloblib canvas instance
         The drawing canvas to interact with
        frame : QWidget
         The QT frame that the canvas is embedded within.
        """
        self.buttons = {}
        self.basedir = None
        NavigationToolbar2QT.__init__(self, canvas, frame)
        if name is not None:
            self.setWindowTitle(name)
        self.setIconSize(QtCore.QSize(25, 25))
        self.layout().setSpacing(1)
        self.setFocusPolicy(Qt.StrongFocus)
Example #37
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.frame = QWidget()
        self.canvas = MplCanvas()
        self.canvas.setParent(self.frame)
        self.mpltoolbar = Navigationtoolbar(self.canvas, self.frame)
        self.vbl = QtGui.QVBoxLayout()
        self.vbl.addWidget(self.canvas)
        self.vbl.addWidget(self.mpltoolbar)
        self.setLayout(self.vbl)

        self.mpltoolbar.toggleViewAction()
Example #38
0
    def __init__(self, parent = None, enableAutoScale = True, enableCSV = False, enableEdit = True, doublePlot = False, layoutDir = 'h'):
        QtGui.QWidget.__init__(self, parent)
        if doublePlot:
            self.canvas = DoubleMyMplCanvas()
        else:
            self.canvas = MyMplCanvas()
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
#        self.toolbar.hide()
        self.installEventFilter(EventFilter(self))

        if layoutDir == 'v':
            self.toolbar.setOrientation(QtCore.Qt.Vertical)
            self.layout = QtGui.QHBoxLayout()


        elif layoutDir == 'h':
            self.layout = QtGui.QVBoxLayout()
#            self.layout.addWidget(self.canvas)
#            self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.canvas)
        self.setLayout(self.layout)

        ##########################

        self.dataLabels = None

        ###########SAVING FIGURE TO CLIPBOARD##########
        self.cb = None #will be used for the clipboard
        self.tempPath = getHomeDir()
        self.tempPath = os.path.join(self.tempPath,'tempMPL.png')

        if enableEdit:
            self.enableEdit()

        self.lineDict = None
        self.addLegend = False


        self.x = None#used for picker
        self.y = None

        #######SAVING FIGURE DATA############################
        if enableCSV:
            self.enableCSV()


        ########### HELPER FUNCTIONS #########################
        self.clearPlotAction = QtGui.QAction("Clear Plot", self)
        self.addAction(self.clearPlotAction)
        QtCore.QObject.connect(self, QtCore.SIGNAL("triggered()"), self.clearPlot)
Example #39
0
    def __init__(self, canvas, frame, name=None):
        """ Create a new toolbar object

        Parameters
        ----------
        data_collection : DataCollection instance
         The data collection that this toolbar is meant to edit.
         The toolbar looks to this collection for the available subsets
         to manipulate.
        canvas : Maptloblib canvas instance
         The drawing canvas to interact with
        frame : QWidget
         The QT frame that the canvas is embedded within.
        """
        self.buttons = {}
        self.basedir = None
        NavigationToolbar2QT.__init__(self, canvas, frame)
        if name is not None:
            self.setWindowTitle(name)
        self.setIconSize(QtCore.QSize(25, 25))
        self.layout().setSpacing(1)
        self.setFocusPolicy(Qt.StrongFocus)
        self._idKey = None
Example #40
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.atten = -1
        self.ui.atten.setValue(self.atten)
        self.resnum = 0
        self.indx = 0

        QObject.connect(self.ui.open_browse, SIGNAL("clicked()"),
                        self.open_dialog)
        QObject.connect(self.ui.save_browse, SIGNAL("clicked()"),
                        self.save_dialog)
        QObject.connect(self.ui.atten, SIGNAL("valueChanged(int)"),
                        self.setnewatten)
        QObject.connect(self.ui.savevalues, SIGNAL("clicked()"),
                        self.savevalues)
        QObject.connect(self.ui.jumptores, SIGNAL("clicked()"), self.jumptores)

        try:
            config = ConfigParser.ConfigParser()
            config.read('/home/data/MEC/20180620/wsData.cfg')
            fl = 'FL6b'
            ws_FN = config.get(fl, 'widesweep_FN')
            ws_freqs_all_FN = config.get(fl, 'ws_freqs_all_FN')
            ws_freqs_good_FN = config.get(fl, 'ws_freqs_good_FN')

            #path='/home/data/MEC/20180618/'
            #ws_FN = 'HypatiaFL8_WS.txt'
            #ws_freqs_all_FN = 'HypatiaFL8_WS-freqs-all.txt'
            #ws_freqs_good_FN = 'HypatiaFL8_WS-freqs-good.txt'
            self.widesweep = numpy.loadtxt(ws_FN)  #freq, I, Q
            self.widesweep_goodFreqs = numpy.loadtxt(ws_freqs_good_FN,
                                                     usecols=[2])
            self.widesweep_allResIDs, self.widesweep_allFreqs = numpy.loadtxt(
                ws_freqs_all_FN, usecols=[0, 2], unpack=True)
            self.h5resID_offset = config.getint(fl, 'h5resID_offset')
            self.wsresID_offset = config.getint(fl, 'wsresID_offset')
            self.widesweep_allResIDs += self.wsresID_offset
        except (IOError, ConfigParser.NoSectionError):
            print 'Could not load widewseep data :-('
            self.widesweep = None
            self.h5resID_offset = 0
            self.wsresID_offset = 0

        self.navi_toolbar = NavigationToolbar(self.ui.plot_3.canvas, self)
        self.ui.plot_3.canvas.setFocusPolicy(Qt.ClickFocus)
        cid = self.ui.plot_3.canvas.mpl_connect('key_press_event',
                                                self.zoom_plot_3)
Example #41
0
    def __init__(self, m4du):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.m4du = m4du

        srEngineMap = dict([(key, spatialRelationClassifier.engineMap[key])
                            for key in [
                                "across", "through", "past", "around", "to",
                                "out", "towards", "away from"
                            ]])

        verbEngineMap = dict([(key, spatialRelationClassifier.engineMap[key])
                              for key in ["turnLeft", "turnRight", "straight"]
                              ])

        self.describe_window = describe.MainWindow(verbEngineMap, srEngineMap)
        self.describe_window.show()

        self.figure = mpl.figure()
        self.oldParent = self.figure.canvas.parent()
        self.figure.canvas.setParent(self)
        self.matplotlibFrame.layout().addWidget(self.figure.canvas)
        self.toolbar = NavigationToolbar2QT(self.figure.canvas, self)
        self.addToolBar(self.toolbar)

        plot_map_for_model(self.m4du)

        self.bot = utbot.utbot()
        self.bot.spawn_bot("USARBot.MDS", (-7.68, -21.44, 18.24), (0, 0, 1.58))

        self.timer = QTimer()
        self.timer.setSingleShot(False)
        self.timer.setInterval(300)
        self.timer.start()

        self.connect(self.timer, SIGNAL("timeout()"), self.updateBot)
        self.connect(self.actionReset, SIGNAL("triggered()"), self.reset)

        self.player_location_plot, = mpl.plot([], [],
                                              '-',
                                              linewidth=4,
                                              color="red")
        self.selected_landmark_plot, = mpl.plot([], [],
                                                '*',
                                                markersize=10,
                                                color="blue")

        self.last_describe_time = datetime.now()
        self.last_describe_loc = None
        self.reset()
    def Plot_Function(self):

        """
            Clears Matplotlib Widget Canvas
            
            Adds 3 subplots
            
            plots Difference Data
            
            sharex - shares x axis between subplots
            """
        # self.legend.remove()

        # Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
        self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
        self.navi_toolbar.clear()

        # Adds Buttons
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("home.png"), "Home", self.navi_toolbar.home)
        # a.setToolTip('returns axes to original position')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("move.png"), "Pan", self.navi_toolbar.pan)
        a.setToolTip("Pan axes with left mouse, zoom with right")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("zoom_to_rect.png"), "Zoom", self.navi_toolbar.zoom)
        a.setToolTip("Zoom to Rectangle")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("filesave.png"), "Save", self.navi_toolbar.save_figure)
        a.setToolTip("Save the figure")

        self.toolbar_grid.addWidget(self.navi_toolbar)

        self.top_xval = self.top_data[self.top_data.dtype.names[self.top_xcombo.currentIndex()]]
        self.top_yval = self.top_data[self.top_data.dtype.names[self.top_ycombo.currentIndex()]]
        self.yval = self.yval - np.median(self.yval)

        x1 = np.linspace(0.0, 5.0)
        y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
        y2 = np.cos(3 * np.pi * x1) * np.exp(-x1)
        y3 = np.cos(4 * np.pi * x1) * np.exp(-x1)
        self.mpl.canvas.fig.clear()

        self.plot1 = self.mpl.canvas.fig.add_subplot(3, 1, 1)
        # self.plot1.plot(self.top_xval,self.top_yval)

        self.plot2 = self.mpl.canvas.fig.add_subplot(3, 1, 2, sharex=self.plot1)
        self.plot2.plot(x1, y2)

        self.plot3 = self.mpl.canvas.fig.add_subplot(3, 1, 3, sharex=self.plot1)
        self.plot3.plot(x1, y3)
Example #43
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)

        self.nodeModel = nodeModel.Model(self.nodeTable)
        self.nodeResultsModel = nodeResultsModel.Model(self.nodeResultsTable)
        self.factorResultsModel = factorResultsModel.Model(
            self.factorResultsTable)
        self.featureModel = featureModel.Model(self.featureTable)
        self.entropyMetricModel = entropyMetricModel.Model(
            self.entropyMetricTable)

        self.windowManager = WindowManager(self.windowsMenu)
        self.contextWindow = context3d.MainWindow()
        #self.context3dFrame.layout().addWidget(self.contextWindow.centralWidget())
        self.contextWindow.setWindowTitle(self.contextWindow.windowTitle() +
                                          " - Node Feature Weights")
        #self.contextWindow.show()
        self.windowManager.addWindow(self.contextWindow)

        self.figure = mpl.figure()
        self.axes = self.figure.gca()
        self.axes.set_aspect("equal")
        self.oldParent = self.figure.canvas.parent()
        self.figure.canvas.setParent(self)
        self.matplotlibFrame.layout().addWidget(self.figure.canvas)
        self.toolbar = NavigationToolbar2QT(self.figure.canvas, self)
        self.addToolBar(self.toolbar)
        self.limits = [-20, 30, 10, 51]
        self.restoreLimits()
        self.figure.canvas.mpl_connect('draw_event', self.updateLimits)

        self.cf_obj = None

        self.connect(
            self.nodeTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectNode)
        self.connect(
            self.nodeResultsTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectNodeResult)

        self.connect(
            self.factorResultsTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectFactorResult)
Example #44
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.canvas = MplCanvas()
        self.vbl = QtGui.QVBoxLayout()
        self.ntb = NavigationToolbar(self.canvas, parent)
        self.ntb.hide()
        self.vbl.addWidget(self.ntb)
        self.vbl.addWidget(self.canvas)
        self.setLayout(self.vbl)
        self.dataX = []
        self.dataY = []
        self.data1 = []
        self.data2 = []
        self.count = 0
        self.flag_newdata = False
        self.initDataGenerator()
Example #45
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)

        self.figure = mpl.figure()
        self.axes = self.figure.gca()
        self.axes.set_aspect("equal")
        self.oldParent = self.figure.canvas.parent()
        self.figure.canvas.setParent(self)
        self.matplotlibFrame.layout().addWidget(self.figure.canvas)
        self.toolbar = NavigationToolbar2QT(self.figure.canvas, self)
        self.addToolBar(self.toolbar)
        self.limits = None
        #self.figure.canvas.mpl_connect('draw_event', self.updateLimits)

        self.esdcModel = esdcTreeModel.Model(self.esdcTreeView)
        self.factorModel = factorModel.Model(self.factorTable)
        self.nodeForFactorModel = nodeForFactorModel.Model(self.nodeTable)
        self.gsModel = groundingsModel.Model(self.groundingSpaceTable)
        self.groundingSpace = None

        self.connect(
            self.groundingSpaceTable.selectionModel(),
            SIGNAL("selectionChanged (QItemSelection,QItemSelection)"),
            self.selectGrounding)

        self.connect(
            self.esdcTreeView.selectionModel(),
            SIGNAL("selectionChanged (QItemSelection,QItemSelection)"),
            self.selectEsdc)

        self.connect(
            self.factorTable.selectionModel(),
            SIGNAL("selectionChanged (QItemSelection,QItemSelection)"),
            self.selectFactor)

        self.connect(
            self.nodeTable.selectionModel(),
            SIGNAL("selectionChanged (QItemSelection,QItemSelection)"),
            self.selectNode)

        self.connect(self.pdfButton, SIGNAL("clicked()"), self.saveToPdf)

        self.connect(self.latexButton, SIGNAL("clicked()"), self.saveToLatex)

        self.baseWindowTitle = "GGG Browser"
Example #46
0
    def __init__(self, parent = None):
        # initialization of the superclass
        super(ModellerMainWindow, self).__init__(parent)
        # setup the GUI --> function generated by pyuic4
        self.setupUi(self)
        #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
        self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
        #self.navi_toolbar.clear()
        
 # Add the x,y location widget at the right side of the toolbar
 # The stretch factor is 1 which means any resizing of the toolbar
 # will resize this label instead of the buttons.
#        self.navi_toolbar.locLabel = QtGui.QLabel( "", self )
#        self.navi_toolbar.locLabel.setAlignment(QtCore.Qt.AlignLeft)
#        self.navi_toolbar.locLabel.setSizePolicy(
#        QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
#                           QtGui.QSizePolicy.Expanding))
#        labelAction = self.navi_toolbar.addWidget(self.navi_toolbar.locLabel)
#        labelAction.setVisible(True)
#Adds Buttons
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home',
                                        self.navi_toolbar.home)
        #a.setToolTip('returns axes to original position')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan',
                                        self.navi_toolbar.pan)
        a.setToolTip('Pan axes with left mouse, zoom with right')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
                                        self.navi_toolbar.zoom)
        a.setToolTip('Zoom to Rectangle')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save',
                           self.navi_toolbar.save_figure)
        a.setToolTip('Save the figure')

        #Button_layout is a QT desginer Grid Layout.
        self.toolbar_grid.addWidget(self.navi_toolbar)
        self.Button_Definitions()
        
        #Run Radio Toggle Code to grey / allow relevant options
        self.radioButton_2d.click()
        self.radioButton_res.click()
        self.MagRes2D3Dtoggle()
Example #47
0
    def __init__(self,):
        QtGui.QWidget.__init__(self)
        self.figure = Figure(facecolor=(1, 1, 1), tight_layout=True)

        self.ax = self.figure.add_subplot(111)

        # Canvas
        self.canvas = FigureCanvas(self.figure)
        self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Expanding)
        self.canvas.updateGeometry()

        # Navigation
        self.navi_toolbar = NavigationToolbar(self.canvas, self)
        self.navi_toolbar.setOrientation(QtCore.Qt.Vertical)
        # Fixed with, otherwise navigation bar resize arbitrary
        self.navi_toolbar.setFixedWidth(40)

        self.vbl = QtGui.QHBoxLayout()
        self.vbl.addWidget(self.navi_toolbar)
        self.vbl.addWidget(self.canvas)
        self.setLayout(self.vbl)
Example #48
0
      def __init__(self, parent = None):
           # initialization of Qt MainWindow widget
           QtGui.QWidget.__init__(self, parent)

           # set the canvas to the Matplotlib widget
           self.canvas = Rt60Canvas()

           # create a vertical box layout
           self.vbl = QtGui.QVBoxLayout()

           # add rt60 widget to vertical box
           self.vbl.addWidget(self.canvas)

           # add interactive navigation
           self.navi_toolbar = NavigationToolbar(self.canvas, self)
           self.vbl.addWidget(self.navi_toolbar)

           # bind events related to drawing lines
           self.canvas.mpl_connect('button_press_event', self.on_press)
           self.canvas.mpl_connect('button_release_event', self.on_release)
           self.canvas.mpl_connect('motion_notify_event', self.on_motion)

           # set the layout to th vertical box
           self.setLayout(self.vbl)

           # no buttons pressed
           self.press = None


           # the line that users get to draw
           self.linex = [0]
           self.liney = [0]
           self.line, = self.canvas.ax.plot(self.linex, self.liney)
           self.line.set_color("red")
           self.line.set_linewidth(1.5)
           self.line.set_linestyle('-')
           
           # initialize annotation
           self.status_text = self.canvas.ax.text(0.45, 0.9, '', transform=self.canvas.ax.transAxes,size=14,ha='center')
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow):

        
        """Customization for Qt Designer created window"""
    
        def ClearPlot(self):
            self.mpl.canvas.ax.clear()
            self.mpl.canvas.draw()
            
        def copy_to_clipboard(self):
            pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas)
            QtGui.QApplication.clipboard().setPixmap(pixmap)
            
            
        def Open_Geoplot(self):
            self.fname = QtGui.QFileDialog.getOpenFileName()
            
        def Plot_Function(self):
            #Get values from Options Grid
            grid_length = self.TravL_val.value()
            grid_width = self.GridL_val.value()
            sample_interval = self.TravI_val.value()
            traverse_interval = self.GridI_val.value()
            
            self.output = Load_Comp(self.fname,grid_length,grid_width,sample_interval,traverse_interval)
            self.mpl.canvas.ax.clear()
            print np.shape(self.output)
            self.mpl.canvas.ax.imshow(self.output,cmap=plt.cm.Greys,extent=[0,grid_length,grid_width,0], aspect='equal',interpolation='none',vmin = self.neg_val.value(), vmax = self.pos_val.value())                        
            self.mpl.canvas.draw()
            
        def Plot_Median_Filter(self):
            grid_length = self.TravL_val.value()
            grid_width = self.GridL_val.value()
            sample_interval = self.TravI_val.value()
            traverse_interval = self.GridI_val.value()
            
            self.output = Load_Comp(self.fname,grid_length,grid_width,sample_interval,traverse_interval)
            self.filter_output = median_filter(self.output)            
            self.mpl.canvas.ax.clear()
            print np.shape(self.output)
            self.mpl.canvas.ax.imshow(self.filter_output,cmap=plt.cm.Greys,extent=[0,grid_length,grid_width,0], aspect='equal',interpolation='none',vmin = self.neg_val.value(), vmax = self.pos_val.value())                        
            self.mpl.canvas.draw()
            
        def plot_options(self):
            self.neg_label = QtGui.QLabel('Neg Value', self)
            self.neg_val = QtGui.QDoubleSpinBox(self)
            self.neg_val.setRange(-100, 100)
            self.neg_val.setValue(-1)
            
            self.pos_label = QtGui.QLabel('Pos Value', self)            
            self.pos_val = QtGui.QDoubleSpinBox(self)
            self.pos_val.setRange(-100, 100)
            self.pos_val.setValue(2)
            
            self.TravL_label = QtGui.QLabel('Trav Length', self)
            self.TravL_val = QtGui.QDoubleSpinBox(self)
            self.TravL_val.setRange(0, 1000)
            self.TravL_val.setValue(30)
            
            self.TravI_label = QtGui.QLabel('Sample Interval', self)
            self.TravI_val = QtGui.QDoubleSpinBox(self)
            self.TravI_val.setValue(0.25)
            
            self.GridL_label = QtGui.QLabel('Grid Width', self)
            self.GridL_val = QtGui.QDoubleSpinBox(self)
            self.GridL_val.setRange(0, 1000)
            self.GridL_val.setValue(30)
            
            self.GridI_label = QtGui.QLabel('Traverse Interval', self)
            self.GridI_val = QtGui.QDoubleSpinBox(self)
            self.GridI_val.setValue(1)
            
            self.Grid_horizontal_Layout_1.addWidget(self.TravL_label)
            self.Grid_horizontal_Layout_1.addWidget(self.TravL_val)
            self.Grid_horizontal_Layout_1.addWidget(self.TravI_label)
            self.Grid_horizontal_Layout_1.addWidget(self.TravI_val)
            
            self.Grid_horizontal_Layout_2.addWidget(self.GridL_label)
            self.Grid_horizontal_Layout_2.addWidget(self.GridL_val)
            self.Grid_horizontal_Layout_2.addWidget(self.GridI_label)
            self.Grid_horizontal_Layout_2.addWidget(self.GridI_val)
            
            self.Grid_horizontal_Layout_3 = QtGui.QHBoxLayout()
            self.Grid_horizontal_Layout_3.setObjectName("Grid_horizontal_Layout_3")
            self.Options_Grid.addLayout(self.Grid_horizontal_Layout_3, 2, 0, 1, 1)
        
            self.Grid_horizontal_Layout_3.addWidget(self.neg_label)
            self.Grid_horizontal_Layout_3.addWidget(self.neg_val)
            self.Grid_horizontal_Layout_3.addWidget(self.pos_label)
            self.Grid_horizontal_Layout_3.addWidget(self.pos_val)
            
            
        def Button_Definitions(self):
            self.firstrun=True
            
            self.Open_button = QtGui.QPushButton('Open', self)
            self.fname = self.Open_button.clicked.connect(self.Open_Geoplot)
            self.Button_Layout.addWidget(self.Open_button)
            
            self.pushButton_plot.clicked.connect(self.Plot_Function)
            self.pushButton_clear.clicked.connect(self.ClearPlot)
            QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.Plot_Function)
            
            self.Save_button = QtGui.QPushButton('Save as .txt',self)
            self.Save_button.clicked.connect(self.save_as_txt)
            self.Button_Layout.addWidget(self.Save_button)          
            
            self.pushButton = QtGui.QPushButton('Median Filter',self)
            self.pushButton.clicked.connect(self.Plot_Median_Filter)
            self.pushButton_clear.clicked.connect(self.ClearPlot)
            #QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.Plot_Function)  
            
            QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard)
    
        def save_as_txt(self):
            self.txt_name = QtGui.QFileDialog.getSaveFileName(self)
            np.savetxt(self.txt_name + '.txt', self.output)
        
        
                            
        
        
        def __init__(self, parent = None):
            # initialization of the superclass
            super(ArchaeoPYMainWindow, self).__init__(parent)
            # setup the GUI --> function generated by pyuic4
            self.setupUi(self)
            #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
            self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
            self.navi_toolbar.clear()
    
        #Adds Buttons
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home',
                                            self.navi_toolbar.home)
            #a.setToolTip('returns axes to original position')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan',
                                            self.navi_toolbar.pan)
            a.setToolTip('Pan axes with left mouse, zoom with right')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
                                            self.navi_toolbar.zoom)
            a.setToolTip('Zoom to Rectangle')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save',
                               self.navi_toolbar.save_figure)
            a.setToolTip('Save the figure')
    
            #Button_layout is a QT desginer Grid Layout.
            self.toolbar_grid.addWidget(self.navi_toolbar)
            self.Button_Definitions()
            self.plot_options()
Example #50
0
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow):

        
        """Customization for Qt Designer created window"""
    
        def ClearPlot(self):
            self.mpl.canvas.ax.clear()
            self.mpl.canvas.draw()
            #Clears Legend
                       
        def copy_to_clipboard(self):
            pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas)
            QtGui.QApplication.clipboard().setPixmap(pixmap)
        
        def Open_File(self):
            self.fname = QtGui.QFileDialog.getOpenFileName()
            #Opes File
            with open(self.fname, 'r') as f:
                self.num_cols = len(f.readline().split(','))
                f.seek(0)
                self.array = np.genfromtxt(f, dtype=float, delimiter=',', skiprows=1, filling_values=np.nan)

            self.chart_title.clear() #Display file path in GUI
            self.chart_title.setText(self.fname)
            #print self.array


        def regrid(self): #Regrid CMD data
            array = self.array #set data
            num_cols = self.num_cols #set number of columns
            fname = self.fname #set filename
            if self.hcp_config.isChecked: #set Coil orientation
                config = 'HCP'
            else:
                config = 'VCP'
            grid = self.grid.text() #set grid(s) to be regridded
            samples_int = float(self.samples_int.text()) #Sampling Interval
            samples_start = float(self.samples_start.text()) #Sample starting position
            samples_stop = float(self.samples_stop.text()) #Sample ending position
            no_samples = (samples_stop - samples_start + samples_int) / samples_int #number of amples down the line     
            traverses_start = float(self.trav_start.text()) #Starting traverse number
            traverses_stop = float(self.trav_stop.text()) #Ending traverse number
            no_traverses = (traverses_stop - traverses_start + float(self.trav_int.text())) / float(self.trav_int.text()) #Number of traverses
            
            #Regrid data
            regrid_cmd(fname, config, grid, array, num_cols, samples_start, samples_stop, no_samples, traverses_start, traverses_stop, no_traverses)
            
                              
        def button_grid(self): #Defines button and layout 
            #self.firstrun=True
            self.buttons_layout = QtGui.QGridLayout()
            self.buttons_box = QtGui.QGroupBox()
            self.buttons_box.setLayout(self.buttons_layout)

            self.survey_layout = QtGui.QGridLayout()
            self.survey_box = QtGui.QGroupBox()
            self.survey_box.setLayout(self.survey_layout)
        
            #File Properties
            self.Grid_horizontal_Layout_2.addWidget(self.buttons_box, 1)
            string = '<span style=" font-size:10pt;; font-weight:600;">File Settings</span>'       
            self.buttons_layout_text = QtGui.QLabel(string, self)             
            
            self.buttons = QtGui.QButtonGroup()            
            self.open_button = QtGui.QPushButton('Open', self)
            self.buttons.addButton(self.open_button)
            self.open_button.clicked.connect(self.Open_File)
            self.regrid_button = QtGui.QPushButton('Regrid', self)
            self.buttons.addButton(self.regrid_button)
            self.regrid_button.clicked.connect(self.regrid)
            self.clear_button = QtGui.QPushButton('Clear', self)
            self.buttons.addButton(self.clear_button)
            self.clear_button.clicked.connect(self.ClearPlot)
            self.chart_title = QtGui.QLineEdit(self)
            self.config_lbl = QtGui.QLabel('Orientation', self)
            self.hcp_config = QtGui.QRadioButton('HCP', self)
            self.vcp_config = QtGui.QRadioButton('VCP', self)
            self.grid = QtGui.QLineEdit(self)
            self.grid.setText('Enter Grid Number')
            

            self.buttons_layout.addWidget(self.buttons_layout_text, 0,0,1,4)                      
            self.buttons_layout.addWidget(self.open_button, 1,0)
            self.buttons_layout.addWidget(self.regrid_button, 2,0)
            self.buttons_layout.addWidget(self.clear_button, 3,0)
            self.buttons_layout.addWidget(self.chart_title, 4,0)
            self.buttons_layout.addWidget(self.config_lbl, 1,1)
            self.buttons_layout.addWidget(self.hcp_config, 2,1)
            self.buttons_layout.addWidget(self.vcp_config, 3,1)
            self.buttons_layout.addWidget(self.grid, 4,1)
            

            #survey parameters
            self.Grid_horizontal_Layout_2.addWidget(self.survey_box, 1)
            string = '<span style=" font-size:10pt;; font-weight:600;">Survey Parameters</span>'       
            self.survey_layout_text = QtGui.QLabel(string, self)
            self.survey_buttons = QtGui.QButtonGroup()
                               
            self.samples_start_lbl = QtGui.QLabel('Samples Start Position')
            self.samples_start = QtGui.QLineEdit(self)
        
            self.samples_stop_lbl = QtGui.QLabel('Samples End Position')
            self.samples_stop = QtGui.QLineEdit(self)

            self.samples_int_lbl = QtGui.QLabel('Sampling Interval')
            self.samples_int = QtGui.QLineEdit(self)

            self.trav_start_lbl = QtGui.QLabel('Traverses Start Position')
            self.trav_start = QtGui.QLineEdit(self)

            self.trav_stop_lbl = QtGui.QLabel('Traverses End Position')
            self.trav_stop = QtGui.QLineEdit(self)

            self.trav_int_lbl = QtGui.QLabel('Traverse Interval')
            self.trav_int = QtGui.QLineEdit(self)
                        
            self.survey_layout.addWidget(self.survey_layout_text, 0,0,1,2)
            self.survey_layout.addWidget(self.samples_start_lbl, 1,0)
            self.survey_layout.addWidget(self.samples_start, 1,1)
            self.survey_layout.addWidget(self.samples_stop_lbl, 2,0)
            self.survey_layout.addWidget(self.samples_stop, 2,1)
            self.survey_layout.addWidget(self.samples_int_lbl, 3,0)
            self.survey_layout.addWidget(self.samples_int,3,1)              
            self.survey_layout.addWidget(self.trav_start_lbl, 4,0)
            self.survey_layout.addWidget(self.trav_start, 4,1)
            self.survey_layout.addWidget(self.trav_stop_lbl, 5,0)
            self.survey_layout.addWidget(self.trav_stop, 5,1)
            self.survey_layout.addWidget(self.trav_int_lbl, 6,0)
            self.survey_layout.addWidget(self.trav_int, 6,1)

                  
        def __init__(self, parent = None):
            # initialization of the superclass
            super(ArchaeoPYMainWindow, self).__init__(parent)
            # setup the GUI --> function generated by pyuic4
            self.setupUi(self)
            #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
            self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
            self.navi_toolbar.clear()
    
        #Adds Buttons
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home',
                                            self.navi_toolbar.home)
            #a.setToolTip('returns axes to original position')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan',
                                            self.navi_toolbar.pan)
            a.setToolTip('Pan axes with left mouse, zoom with right')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
                                            self.navi_toolbar.zoom)
            a.setToolTip('Zoom to Rectangle')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save',
                               self.navi_toolbar.save_figure)
            a.setToolTip('Save the figure')
            
            QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard)

            
            #self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label')
            
            #Button_layout is a QT desginer Grid Layout.
            self.toolbar_grid.addWidget(self.navi_toolbar)
            self.button_grid()
class TraverseMainWindow(QtGui.QMainWindow, Ui_MainWindow):
    def ClearPlot(self):
        self.mpl.canvas.ax.clear()
        self.mpl.canvas.draw()

    def copy_to_clipboard(self):
        pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas)
        QtGui.QApplication.clipboard().setPixmap(pixmap)

    def press_open(self):
        self.fname = QtGui.QFileDialog.getExistingDirectory(self, "Select Project")
        open_project(self.fname, self)
        self.statusbar.showMessage("press_open returned")
        self.repaint()

    def Open_File(self):
        self.fname = QtGui.QFileDialog.getOpenFileName()
        # self.f = open(self.fname, 'rb')
        with open(self.fname, "r") as f:
            num_cols = len(f.readline().split("	")) - 1
            f.seek(0)
            data = np.genfromtxt(
                f, names=True, delimiter="	", dtype=None, filling_values=np.nan, usecols=(range(0, num_cols))
            )
            return data
        # print data
        # print "beak"
        # return data
        # print data
        # print "break"

    def top_data(self):
        # print "beak"
        self.top_data = self.Open_File()
        print self.top_data.dtype.names
        # print data
        self.top_x = self.top_data.dtype.names
        # print self.data[self.data.dtype.names[1]]
        # print self.data[self.data.dtype.names[2]]
        # return self.top_x
        self.top_y = self.top_data.dtype.names
        # return self.top_y
        self.top_xcombo.clear()
        self.top_xcombo.addItems(self.top_x)
        self.top_ycombo.clear()
        self.top_ycombo.addItems(self.top_y)

        # Clears Legend
        # self.legend_definitions()

    def legend_definitions(self):
        self.handles = []
        self.labels = []

        self.colors = itertools.cycle(["b", "g", "r", "c", "m", "y", "b"])
        self.markers = itertools.cycle([".", "D", "p", "*", "+"])

        self.legend = self.mpl.canvas.fig.legend(self.handles, self.labels, "upper right")

    def openInputDialog(self):
        x_axis, result = QtGui.QInputDialog.getText(self, "X axis", "Specify units")
        if result:
            self.x_axis = x_axis
        y_axis, result = QtGui.QInputDialog.getText(self, "Y axis", "Specify units")
        if result:
            self.y_axis = y_axis

    def button_grid(self):
        # An Expanding Spacer Item to be used anywhere..
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.toolbar_grid.addItem(spacerItem, 0, 0, 1, 1)
        self.toolbar_grid.addItem(spacerItem, 0, 4, 1, 1)

        # self.Grid_horizontal_Layout_2.addItem(spacerItem, 0)
        # self.Grid_horizontal_Layout_2.addItem(spacerItem, 4)

        # Layout for processing toolbbox
        self.top_plot_layout = QtGui.QGridLayout()
        self.top_plot_box = QtGui.QGroupBox()
        self.top_plot_box.setLayout(self.top_plot_layout)

        self.middle_plot_layout = QtGui.QGridLayout()
        self.middle_plot_box = QtGui.QGroupBox()
        self.middle_plot_box.setLayout(self.middle_plot_layout)

        self.bottom_plot_layout = QtGui.QGridLayout()
        self.bottom_plot_box = QtGui.QGroupBox()
        self.bottom_plot_box.setLayout(self.bottom_plot_layout)

        # Traverse selector grid box
        self.Grid_horizontal_Layout_2.addWidget(self.top_plot_box, 0)
        # self.toolbar_grid.addLayout(self.top_plot_layout, 0, 1, 1, 1)

        string = '<span style=" font-size:14pt;; font-weight:600;">Top Plot</span>'
        self.top_plot_layout_text = QtGui.QLabel(string, self)

        # Defines push buttons for top plot
        self.top_plot_buttons = QtGui.QButtonGroup()
        self.top_open_button = QtGui.QPushButton("Open", self)
        self.top_fname = self.top_open_button.clicked.connect(self.top_data)
        self.top_plot_buttons.addButton(self.top_open_button)
        self.top_plot_button = QtGui.QPushButton("Plot", self)
        # self.top_fname = self.top_open_button.clicked.connect(self.Open_File)
        self.top_plot_buttons.addButton(self.top_plot_button)
        self.top_clear_button = QtGui.QPushButton("Clear", self)
        # self.top_fname = self.top_open_button.clicked.connect(self.Open_File)
        self.top_plot_buttons.addButton(self.top_clear_button)
        self.top_plot_input = QtGui.QButtonGroup()
        self.top_units = QtGui.QPushButton("Input Units", self)
        self.top_units.clicked.connect(self.openInputDialog)

        # Defines combo boxes for top plot
        self.top_plot_combo = QtGui.QButtonGroup()
        self.top_xcombo = QtGui.QComboBox()
        self.top_xcombo.addItems("X")
        self.top_xcombo_lbl = QtGui.QLabel("X Values", self)
        self.top_ycombo = QtGui.QComboBox()
        self.top_ycombo.addItems("Y")
        self.top_ycombo_lbl = QtGui.QLabel("Y Values", self)

        self.top_plot_layout.addWidget(self.top_plot_layout_text, 0, 0, 1, 4)
        self.top_plot_layout.addWidget(self.top_open_button, 1, 0)
        self.top_plot_layout.addWidget(self.top_plot_button, 2, 0)
        self.top_plot_layout.addWidget(self.top_clear_button, 3, 0)
        self.top_plot_layout.addWidget(self.top_units, 4, 0)

        self.top_plot_layout.addWidget(self.top_xcombo_lbl, 1, 1)
        self.top_plot_layout.addWidget(self.top_xcombo, 2, 1)
        self.top_plot_layout.addWidget(self.top_ycombo_lbl, 3, 1)
        self.top_plot_layout.addWidget(self.top_ycombo, 4, 1)

        self.top_plot_layout.addItem(spacerItem, 0, 0, 1, 1)
        self.top_plot_layout.addItem(spacerItem, 3, 0, 1, 1)

        # 1st Pass Selector Box
        self.Grid_horizontal_Layout_2.addWidget(self.middle_plot_box, 1)
        # self.toolbar_grid.addLayout(self.middle_plot_layout, 0, 2, 1, 1)

        # Title of Box. HTML required to change colour & weight
        string = '<span style=" font-size:14pt;; font-weight:600;">Middle Plot</span>'
        self.middle_plot_layout_text = QtGui.QLabel(string, self)

        self.middle_plot_buttons = QtGui.QButtonGroup()
        self.middle_open_button = QtGui.QPushButton("Open", self)
        self.middle_fname = self.middle_open_button.clicked.connect(self.top_data)
        self.middle_plot_buttons.addButton(self.middle_open_button)
        self.middle_plot_button = QtGui.QPushButton("Plot", self)
        # self.middle_fname = self.middle_open_button.clicked.connect(self.Open_File)
        self.middle_plot_buttons.addButton(self.middle_plot_button)
        self.middle_clear_button = QtGui.QPushButton("Clear", self)
        # self.middle_fname = self.middle_open_button.clicked.connect(self.Open_File)
        self.middle_plot_buttons.addButton(self.middle_clear_button)
        self.middle_plot_input = QtGui.QButtonGroup()
        self.middle_units = QtGui.QPushButton("Input Units", self)
        self.middle_units.clicked.connect(self.openInputDialog)

        # Defines combo boxes for middle plot
        self.middle_plot_combo = QtGui.QButtonGroup()
        self.middle_xcombo = QtGui.QComboBox()
        self.middle_xcombo.addItems("X")
        self.middle_xcombo_lbl = QtGui.QLabel("X Values", self)
        self.middle_ycombo = QtGui.QComboBox()
        self.middle_ycombo.addItems("Y")
        self.middle_ycombo_lbl = QtGui.QLabel("Y Values", self)

        self.middle_plot_layout.addWidget(self.middle_plot_layout_text, 0, 0, 1, 4)
        self.middle_plot_layout.addWidget(self.middle_open_button, 1, 0)
        self.middle_plot_layout.addWidget(self.middle_plot_button, 2, 0)
        self.middle_plot_layout.addWidget(self.middle_clear_button, 3, 0)
        self.middle_plot_layout.addWidget(self.middle_units, 4, 0)

        self.middle_plot_layout.addWidget(self.middle_xcombo_lbl, 1, 1)
        self.middle_plot_layout.addWidget(self.middle_xcombo, 2, 1)
        self.middle_plot_layout.addWidget(self.middle_ycombo_lbl, 3, 1)
        self.middle_plot_layout.addWidget(self.middle_ycombo, 4, 1)

        # Bottom Plot Selector Box
        self.Grid_horizontal_Layout_2.addWidget(self.bottom_plot_box, 2)
        # self.toolbar_grid.addLayout(self.bottom_plot_layout, 0, 3, 1, 1)
        # Title of Box. HTML required to change colour & weight
        string = '<span style=" font-size:14pt;; font-weight:600;">Bottom Plot</span>'
        self.bottom_plot_layout_text = QtGui.QLabel(string, self)

        self.bottom_plot_buttons = QtGui.QButtonGroup()
        self.bottom_open_button = QtGui.QPushButton("Open", self)
        self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File)
        self.bottom_plot_buttons.addButton(self.bottom_open_button)
        self.bottom_plot_button = QtGui.QPushButton("Plot", self)
        # self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File)
        self.bottom_plot_buttons.addButton(self.bottom_plot_button)
        self.bottom_clear_button = QtGui.QPushButton("Clear", self)
        # self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File)
        self.bottom_plot_buttons.addButton(self.bottom_clear_button)
        self.bottom_plot_input = QtGui.QButtonGroup()
        self.bottom_units = QtGui.QPushButton("Input Units", self)
        self.bottom_units.clicked.connect(self.openInputDialog)

        # Defines combo boxes for bottom plot
        self.bottom_plot_combo = QtGui.QButtonGroup()
        self.bottom_xcombo = QtGui.QComboBox()
        self.bottom_xcombo.addItems("X")
        self.bottom_xcombo_lbl = QtGui.QLabel("X Values", self)
        self.bottom_ycombo = QtGui.QComboBox()
        self.bottom_ycombo.addItems("Y")
        self.bottom_ycombo_lbl = QtGui.QLabel("Y Values", self)

        self.bottom_plot_layout.addWidget(self.bottom_plot_layout_text, 0, 0, 1, 4)
        self.bottom_plot_layout.addWidget(self.bottom_open_button, 1, 0)
        self.bottom_plot_layout.addWidget(self.bottom_plot_button, 2, 0)
        self.bottom_plot_layout.addWidget(self.bottom_clear_button, 3, 0)
        self.bottom_plot_layout.addWidget(self.bottom_units, 4, 0)

        self.bottom_plot_layout.addWidget(self.bottom_xcombo_lbl, 1, 1)
        self.bottom_plot_layout.addWidget(self.bottom_xcombo, 2, 1)
        self.bottom_plot_layout.addWidget(self.bottom_ycombo_lbl, 3, 1)
        self.bottom_plot_layout.addWidget(self.bottom_ycombo, 4, 1)

    def Plot_Function(self):

        """
            Clears Matplotlib Widget Canvas
            
            Adds 3 subplots
            
            plots Difference Data
            
            sharex - shares x axis between subplots
            """
        # self.legend.remove()

        # Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
        self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
        self.navi_toolbar.clear()

        # Adds Buttons
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("home.png"), "Home", self.navi_toolbar.home)
        # a.setToolTip('returns axes to original position')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("move.png"), "Pan", self.navi_toolbar.pan)
        a.setToolTip("Pan axes with left mouse, zoom with right")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("zoom_to_rect.png"), "Zoom", self.navi_toolbar.zoom)
        a.setToolTip("Zoom to Rectangle")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("filesave.png"), "Save", self.navi_toolbar.save_figure)
        a.setToolTip("Save the figure")

        self.toolbar_grid.addWidget(self.navi_toolbar)

        self.top_xval = self.top_data[self.top_data.dtype.names[self.top_xcombo.currentIndex()]]
        self.top_yval = self.top_data[self.top_data.dtype.names[self.top_ycombo.currentIndex()]]
        self.yval = self.yval - np.median(self.yval)

        x1 = np.linspace(0.0, 5.0)
        y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
        y2 = np.cos(3 * np.pi * x1) * np.exp(-x1)
        y3 = np.cos(4 * np.pi * x1) * np.exp(-x1)
        self.mpl.canvas.fig.clear()

        self.plot1 = self.mpl.canvas.fig.add_subplot(3, 1, 1)
        # self.plot1.plot(self.top_xval,self.top_yval)

        self.plot2 = self.mpl.canvas.fig.add_subplot(3, 1, 2, sharex=self.plot1)
        self.plot2.plot(x1, y2)

        self.plot3 = self.mpl.canvas.fig.add_subplot(3, 1, 3, sharex=self.plot1)
        self.plot3.plot(x1, y3)

    def keyboard_Definitions(self):

        QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"), self, self.Plot_Function)

        QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard)

    def menubar_definitions(self):
        self.fname = self.Open_button.clicked.connect(self.Open_File)

    def __init__(self, parent=None):
        # initialization of the superclass
        super(TraverseMainWindow, self).__init__(parent)
        # setup the GUI --> function generated by pyuic4
        self.setupUi(self)

        # Button_layout is a QT desginer Grid Layout.

        self.keyboard_Definitions()
        # self.Plot_Function()
        self.button_grid()

        self.statusbar.setEnabled(True)
        self.statusbar.showMessage("Ready")
Example #52
0
 def __init__(self, canvas, parent, coordinates=False):
     NavigationToolbar2QT.__init__(self, canvas, parent, coordinates)
     self.setIconSize(QtCore.QSize(20, 20)) # to change size of icons in toolbar
Example #53
0
    def __init__(self, parent = None, enableAutoScale = False, enableCSV = False, enableEdit = False, doublePlot = False, layoutDir = 'h'):
        QtGui.QWidget.__init__(self, parent)
        if doublePlot:
            self.canvas = DoubleMyMplCanvas()
        else:
            self.canvas = MyMplCanvas()
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        self.iconSize = QtCore.QSize(15,15)
        self.toolbar.setIconSize(self.iconSize)

        self.installEventFilter(EventFilter(self))

        if layoutDir == 'v':
            self.toolbar.setOrientation(QtCore.Qt.Vertical)
            self.layout = QtGui.QHBoxLayout()


        elif layoutDir == 'h':
            self.layout = QtGui.QVBoxLayout()
#            self.layout.addWidget(self.canvas)
#            self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.canvas)
        self.setLayout(self.layout)

        ###############ZOOM CONTROLS ################




        #This function has been disabled because of the special autoscaling requried for a custom program
        #FIX THIS
        if enableAutoScale:
            print "Enable AutoScale"
            #self.enableAutoScale()


        self.span = SpanSelector(self.canvas.ax, self.onselect, 'horizontal', minspan =0.01,
                                 useblit=True, rectprops=dict(alpha=0.5, facecolor='#C6DEFF') )
        self.hZoom = False
        self.span.visible = False

        self.localYMax = 0
        self.canvas.mpl_connect('button_press_event', self.onclick)

        ###########SAVING FIGURE TO CLIPBOARD##########
        self.cb = None #will be used for the clipboard
        self.tempPath = getHomeDir()
        self.tempPath = os.path.join(self.tempPath,'tempMPL.png')

#        self.mpl2ClipAction = QtGui.QAction("Save to Clipboard",  self)
#        self.mpl2ClipAction.setShortcut("Ctrl+C")
#        self.addAction(self.mpl2ClipAction)
#        QtCore.QObject.connect(self.mpl2ClipAction,QtCore.SIGNAL("triggered()"), self.mpl2Clip)

        if enableEdit:
            self.enableEdit()

        self.lineDict = None
        self.addLegend = False


        #######SAVING FIGURE DATA############################
        if enableCSV:
            self.enableCSV()
Example #54
0
class MPL_Widget(QtGui.QWidget):
    def __init__(self, parent = None, enableAutoScale = False, enableCSV = False, enableEdit = False, doublePlot = False, layoutDir = 'h'):
        QtGui.QWidget.__init__(self, parent)
        if doublePlot:
            self.canvas = DoubleMyMplCanvas()
        else:
            self.canvas = MyMplCanvas()
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        self.iconSize = QtCore.QSize(15,15)
        self.toolbar.setIconSize(self.iconSize)

        self.installEventFilter(EventFilter(self))

        if layoutDir == 'v':
            self.toolbar.setOrientation(QtCore.Qt.Vertical)
            self.layout = QtGui.QHBoxLayout()


        elif layoutDir == 'h':
            self.layout = QtGui.QVBoxLayout()
#            self.layout.addWidget(self.canvas)
#            self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.canvas)
        self.setLayout(self.layout)

        ###############ZOOM CONTROLS ################




        #This function has been disabled because of the special autoscaling requried for a custom program
        #FIX THIS
        if enableAutoScale:
            print "Enable AutoScale"
            #self.enableAutoScale()


        self.span = SpanSelector(self.canvas.ax, self.onselect, 'horizontal', minspan =0.01,
                                 useblit=True, rectprops=dict(alpha=0.5, facecolor='#C6DEFF') )
        self.hZoom = False
        self.span.visible = False

        self.localYMax = 0
        self.canvas.mpl_connect('button_press_event', self.onclick)

        ###########SAVING FIGURE TO CLIPBOARD##########
        self.cb = None #will be used for the clipboard
        self.tempPath = getHomeDir()
        self.tempPath = os.path.join(self.tempPath,'tempMPL.png')

#        self.mpl2ClipAction = QtGui.QAction("Save to Clipboard",  self)
#        self.mpl2ClipAction.setShortcut("Ctrl+C")
#        self.addAction(self.mpl2ClipAction)
#        QtCore.QObject.connect(self.mpl2ClipAction,QtCore.SIGNAL("triggered()"), self.mpl2Clip)

        if enableEdit:
            self.enableEdit()

        self.lineDict = None
        self.addLegend = False


        #######SAVING FIGURE DATA############################
        if enableCSV:
            self.enableCSV()


        ########### HELPER FUNCTIONS #########################
#    def focusOutEvent(self, event):
#        print "Focus Out"

    def focusEvent(self, event):
        self.enableAutoScale()
        self.enableZoom()
        self.enableClip()
        self.enableCSV()
        #print "Focus In %s"%self.canvas.plotTitle

    def lossFocusEvent(self, event):
        self.disableAutoScale()
        self.disableZoom()
        self.disableClip()
        self.disableCSV()
        #print "Focus Out %s"%self.canvas.plotTitle

    def enableClip(self):
        self.mpl2ClipAction = QtGui.QAction("Save to Clipboard",  self)
        self.mpl2ClipAction.setShortcut("Ctrl+C")
        self.addAction(self.mpl2ClipAction)
        QtCore.QObject.connect(self.mpl2ClipAction,QtCore.SIGNAL("triggered()"), self.mpl2Clip)

    def disableClip(self):
        QtCore.QObject.disconnect(self.mpl2ClipAction,QtCore.SIGNAL("triggered()"), self.mpl2Clip)
        self.removeAction(self.mpl2ClipAction)

    def enableEdit(self):
        self.editAction = QtGui.QAction("Edit Line Properties",  self)
        self.editAction.setShortcut("Ctrl+Alt+E")
        self.addAction(self.editAction)
        QtCore.QObject.connect(self.editAction,QtCore.SIGNAL("triggered()"), self.editPlotProperties)

    def disableEdit(self):
        if self.editAction:
            QtCore.QObject.disconnect(self.editAction,QtCore.SIGNAL("triggered()"), self.editPlotProperties)
            self.removeAction(self.editAction)

    def enableZoom(self):
        self.Zoom = QtGui.QAction("Zoom",  self)
        self.Zoom.setShortcut("Ctrl+Z")
        self.addAction(self.Zoom)
        QtCore.QObject.connect(self.Zoom,QtCore.SIGNAL("triggered()"), self.ZoomToggle)

    def disableZoom(self):
        if self.Zoom != None:
            QtCore.QObject.disconnect(self.Zoom,QtCore.SIGNAL("triggered()"), self.ZoomToggle)
            self.removeAction(self.Zoom)

    def disableAutoScale(self):
        if self.actionAutoScale != None:
            QtCore.QObject.disconnect(self.actionAutoScale,QtCore.SIGNAL("triggered()"), self.autoscale_plot)
            self.removeAction(self.actionAutoScale)

    def enableAutoScale(self):
        self.actionAutoScale = QtGui.QAction("AutoScale",  self)#self.MainWindow)
        self.actionAutoScale.setShortcut("Ctrl+A")
        self.addAction(self.actionAutoScale)
        QtCore.QObject.connect(self.actionAutoScale,QtCore.SIGNAL("triggered()"), self.autoscale_plot)


    def enableCSV(self):
        self.saveCSVAction = QtGui.QAction("Save to CSV",  self)
        self.saveCSVAction.setShortcut("Ctrl+Alt+S")
        self.addAction(self.saveCSVAction)
        QtCore.QObject.connect(self.saveCSVAction,QtCore.SIGNAL("triggered()"), self.save2CSV)

    def disableCSV(self):
        QtCore.QObject.disconnect(self.saveCSVAction,QtCore.SIGNAL("triggered()"), self.save2CSV)
        self.removeAction(self.saveCSVAction)

    def setLineDict(self):
        self.lineDict = {}
        lineList = self.canvas.ax.get_lines()
        if lineList > 0:
            for line in lineList:
                self.lineDict[line.get_label()]=line

    def editPlotProperties(self):
        print "Edit Enabled"
        self.setLineDict()
#        if len(self.lineDict) > 0:
        curAx = self.canvas.ax
        if POD(self.lineDict, curAx = curAx, parent = self).exec_():
            if self.addLegend:
                curAx.legend(borderaxespad = 0.03, axespad=0.25)
            self.canvas.format_labels()
            self.canvas.draw()
        else:
            print "Cancel"


    def ZoomToggle(self):
        #self.toolbar.zoom() #this implements the classic zoom
        if self.hZoom:
            self.hZoom = False
            self.span.visible = False
        else:
            self.hZoom = True
            self.span.visible = True

    def autoscale_plot(self):
        #self.toolbar.home() #implements the classic return to home
        self.canvas.ax.autoscale_view(tight = False, scalex=True, scaley=True)
        self.canvas.draw()
        self.emit(QtCore.SIGNAL("autoScaleAxis(bool)"),True)

    def onclick(self, event):
        #sets up the maximum Y level to be displayed after the zoom.
        #if not set then it maxes to the largest point in the data
        #not necessarily the local max
        if event.ydata != None:
            self.localYMax = int(event.ydata)

    def onselect(self, xmin, xmax):
        #print xmin,  xmax
        if self.hZoom:
            self.canvas.ax.set_ylim(ymax = self.localYMax)
            self.canvas.ax.set_xlim(xmin, xmax)
            self.canvas.draw()

    def save2CSV(self):
        path = self.SFDialog()
        if path != None:
            try:
                lines = self.canvas.ax.get_lines()
                data2write = []
                for line in lines:
                    data2write.append(line.get_data()[0])
                    data2write.append(line.get_data()[1])
                print data2write
                data2write = N.array(data2write)
                data2write.dtype = N.float32
                N.savetxt(str(path), N.transpose(data2write), delimiter = ',', fmt='%.4f')
            except:
                try:
                    #this is for the case where the data may not be in float format?
                    N.savetxt(str(path), N.transpose(data2write), delimiter = ',')
                except:
                    print 'Error saving figure data'
                    errorMsg = "Sorry: %s\n\n:%s\n"%(sys.exc_type, sys.exc_value)
                    print errorMsg


    def SFDialog(self):
        fileName = QtGui.QFileDialog.getSaveFileName(self,
                                         "Select File to Save",
                                         "",
                                         "csv Files (*.csv)")
        if not fileName.isEmpty():
            print fileName
            return fileName
        else:
            return None


    def mpl2Clip(self):
        try:
            self.canvas.fig.savefig(self.tempPath)
            tempImg = QtGui.QImage(self.tempPath)
            self.cb = QtGui.QApplication.clipboard()
            self.cb.setImage(tempImg)
        except:
            print 'Error copying figure to clipboard'
            errorMsg = "Sorry: %s\n\n:%s\n"%(sys.exc_type, sys.exc_value)
            print errorMsg
Example #55
0
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow):

        
        """Customization for Qt Designer created window"""
    
        def ClearPlot(self):
            self.mpl.canvas.ax.clear()
            self.mpl.canvas.draw()
            
        def copy_to_clipboard(self):
            pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas)
            QtGui.QApplication.clipboard().setPixmap(pixmap)
            
            
        def Open_Geoplot(self):
            self.fname = QtGui.QFileDialog.getOpenFileName()
            self.Plot_Function()
            
        def Plot_Function(self):
            #Get values from Options Grid
            self.grid_length = self.TravL_val.value()
            self.grid_width = self.GridL_val.value()
            self.sample_interval = self.TravI_val.value()
            self.traverse_interval = self.GridI_val.value()
            
            self.output = Load_Comp(self.fname,self.grid_length,self.grid_width,self.sample_interval,self.traverse_interval)
            self.mpl.canvas.ax.clear()
            print np.shape(self.output)
            self.mpl.canvas.ax.imshow(self.output,cmap=plt.cm.Greys,extent=[0,self.grid_length,self.grid_width,0], aspect='equal',interpolation='none',vmin = self.neg_val.value(), vmax = self.pos_val.value())                        
            self.mpl.canvas.draw()

            
        def plot_options(self):
            self.neg_label = QtGui.QLabel('Neg Value', self)
            self.neg_val = QtGui.QDoubleSpinBox(self)
            self.neg_val.setRange(-100, 100)
            self.neg_val.setValue(-1)
            
            self.pos_label = QtGui.QLabel('Pos Value', self)            
            self.pos_val = QtGui.QDoubleSpinBox(self)
            self.pos_val.setRange(-100, 100)
            self.pos_val.setValue(2)
            
            self.TravL_label = QtGui.QLabel('Trav Length', self)
            self.TravL_val = QtGui.QDoubleSpinBox(self)
            self.TravL_val.setRange(0, 1000)
            self.TravL_val.setValue(30)
            
            self.TravI_label = QtGui.QLabel('Sample Interval', self)
            self.TravI_val = QtGui.QDoubleSpinBox(self)
            self.TravI_val.setValue(0.25)
            
            self.GridL_label = QtGui.QLabel('Grid Width', self)
            self.GridL_val = QtGui.QDoubleSpinBox(self)
            self.GridL_val.setRange(0, 1000)
            self.GridL_val.setValue(30)
            
            self.GridI_label = QtGui.QLabel('Traverse Interval', self)
            self.GridI_val = QtGui.QDoubleSpinBox(self)
            self.GridI_val.setValue(1)
            
            self.Scale_label  = QtGui.QLabel('Scale Value', self)
            self.Scale_val =QtGui.QDoubleSpinBox(self)
            self.Scale_val.setRange(1, 5000)
            self.Scale_val.setValue(500)
            
            self.Clip_label  = QtGui.QLabel('Clipping Value', self)
            self.Clip_val = QtGui.QDoubleSpinBox(self)
            self.Clip_val.setRange(0.1, 100)
            self.Clip_val.setValue(15)
            
            self.Grid_horizontal_Layout_1.addWidget(self.TravL_label)
            self.Grid_horizontal_Layout_1.addWidget(self.TravL_val)
            self.Grid_horizontal_Layout_1.addWidget(self.TravI_label)
            self.Grid_horizontal_Layout_1.addWidget(self.TravI_val)
            
            self.Grid_horizontal_Layout_2.addWidget(self.GridL_label)
            self.Grid_horizontal_Layout_2.addWidget(self.GridL_val)
            self.Grid_horizontal_Layout_2.addWidget(self.GridI_label)
            self.Grid_horizontal_Layout_2.addWidget(self.GridI_val)
            
            self.Grid_horizontal_Layout_3 = QtGui.QHBoxLayout()
            self.Grid_horizontal_Layout_3.setObjectName("Grid_horizontal_Layout_3")
            self.Options_Grid.addLayout(self.Grid_horizontal_Layout_3, 2, 0, 1, 1)
        
            self.Grid_horizontal_Layout_3.addWidget(self.neg_label)
            self.Grid_horizontal_Layout_3.addWidget(self.neg_val)
            self.Grid_horizontal_Layout_3.addWidget(self.pos_label)
            self.Grid_horizontal_Layout_3.addWidget(self.pos_val)
            
            self.Grid_horizontal_Layout_4 = QtGui.QHBoxLayout()
            self.Grid_horizontal_Layout_4.setObjectName("Grid_horizontal_Layout_4")
            self.Options_Grid.addLayout(self.Grid_horizontal_Layout_4, 3, 0, 1, 1)
            
            self.Grid_horizontal_Layout_4.addWidget(self.Scale_label)
            self.Grid_horizontal_Layout_4.addWidget(self.Scale_val)
            self.Grid_horizontal_Layout_4.addWidget(self.Clip_label)
            self.Grid_horizontal_Layout_4.addWidget(self.Clip_val)
            
            
        def Button_Definitions(self):
            self.firstrun=True
            
            self.Open_button = QtGui.QPushButton('Open', self)
            self.fname = self.Open_button.clicked.connect(self.Open_Geoplot)
            self.Button_Layout.addWidget(self.Open_button)
            
            self.Save_button = QtGui.QPushButton('Save as DXF',self)
            self.Save_button.clicked.connect(self.dxf_save_button)
            self.Button_Layout.addWidget(self.Save_button)
            
            self.pushButton_plot.clicked.connect(self.Plot_Function)
            self.pushButton_clear.clicked.connect(self.ClearPlot)
            QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.Plot_Function)
            
            QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard)
            
        def dxf_save_button(self):
            self.dxf_name  = QtGui.QFileDialog.getSaveFileName(self)
            self.Scale = self.Scale_val.value()
            self.Clip = self.Clip_val.value()
            
            QtGui.QMessageBox.about(self, "This May take a second", "Saving DXF's can be slow, please be paient. \n A dialogue will open when finished")
            comp2dxf(self.output,self.dxf_name,self.sample_interval,self.traverse_interval,self.Scale,self.Clip, 'CMP2DXF')
            QtGui.QMessageBox.about(self, "Thanks for waiting", "Sorry about the wait, DXFengine is slow. \n The DXF has been saved. ")        
        
      
            
        def __init__(self, parent = None):
            # initialization of the superclass
            super(ArchaeoPYMainWindow, self).__init__(parent)
            # setup the GUI --> function generated by pyuic4
            self.setupUi(self)
            #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
            self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
            self.navi_toolbar.clear()
    
        #Adds Buttons
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home',
                                            self.navi_toolbar.home)
            #a.setToolTip('returns axes to original position')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan',
                                            self.navi_toolbar.pan)
            a.setToolTip('Pan axes with left mouse, zoom with right')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
                                            self.navi_toolbar.zoom)
            a.setToolTip('Zoom to Rectangle')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save',
                               self.navi_toolbar.save_figure)
            a.setToolTip('Save the figure')
    
            #Button_layout is a QT desginer Grid Layout.
            self.toolbar_grid.addWidget(self.navi_toolbar)
            self.Button_Definitions()
            self.plot_options()
Example #56
0
class MPL_Widget(QtGui.QWidget):
    def __init__(self, parent = None):
        QtGui.QWidget.__init__(self, parent)
        self.canvas = MyMplCanvas()
        #self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
        self.toolbar = NavigationToolbar(self.canvas, self.canvas)
        self.toolbar.hide()
        self.hbox = QtGui.QHBoxLayout()
        #self.hbox.addWidget(self.toolbar)
        self.hbox.addWidget(self.canvas)
        self.setLayout(self.hbox)
        ##########################
        self.hZoom = QtGui.QAction("Zoom",  self)
        self.hZoom.setShortcut("Ctrl+Z")
        self.addAction(self.hZoom)
        QtCore.QObject.connect(self.hZoom,QtCore.SIGNAL("triggered()"), self.ZoomToggle)

        self.actionAutoScale = QtGui.QAction("AutoScale",  self)#self.MainWindow)
        self.actionAutoScale.setShortcut("Ctrl+A")
        self.addAction(self.actionAutoScale)
        QtCore.QObject.connect(self.actionAutoScale,QtCore.SIGNAL("triggered()"), self.autoscale_plot)


        self.installEventFilter(EventFilter(self))

        ###########SAVING FIGURE TO CLIPBOARD##########
        self.cb = None #will be used for the clipboard
        self.tempPath = getHomeDir()
        self.tempPath = os.path.join(self.tempPath,'tempMPL.png')

    def ZoomToggle(self):
        self.toolbar.zoom()

    def autoscale_plot(self):
        self.toolbar.home()

    def mpl2Clip(self):
        try:
            self.canvas.fig.savefig(self.tempPath)
            tempImg = QtGui.QImage(self.tempPath)
            self.cb = QtGui.QApplication.clipboard()
            self.cb.setImage(tempImg)
        except:
            print 'Error copying figure to clipboard'
            errorMsg = "Sorry: %s\n\n:%s\n"%(sys.exc_type, sys.exc_value)
            print errorMsg

    def focusEvent(self, event):
#        self.enableAutoScale()
#        self.enableZoom()
        self.enableClip()
#        self.enableCSV()
        #print "Focus In %s"%self.canvas.plotTitle

    def lossFocusEvent(self, event):
#        self.disableAutoScale()
#        self.disableZoom()
        self.disableClip()
#        self.disableCSV()
        #print "Focus Out %s"%self.canvas.plotTitle

    def enableClip(self):
        self.mpl2ClipAction = QtGui.QAction("Save to Clipboard",  self)
        self.mpl2ClipAction.setShortcut("Ctrl+C")
        self.addAction(self.mpl2ClipAction)
        QtCore.QObject.connect(self.mpl2ClipAction,QtCore.SIGNAL("triggered()"), self.mpl2Clip)

    def disableClip(self):
        QtCore.QObject.disconnect(self.mpl2ClipAction,QtCore.SIGNAL("triggered()"), self.mpl2Clip)
        self.removeAction(self.mpl2ClipAction)
Example #57
0
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow):

    """Customization for Qt Designer created window"""

    def ClearPlot(self):
        self.mpl.canvas.ax.clear()
        self.mpl.canvas.draw()
        # Clears Legend
        self.legend.remove()
        self.legend_definitions()
        self.mpl.canvas.draw()

    def copy_to_clipboard(self):
        pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas)
        QtGui.QApplication.clipboard().setPixmap(pixmap)

    def Open_File(self):
        self.fname = QtGui.QFileDialog.getOpenFileName()
        # Opes File
        with open(self.fname, "r") as f:
            num_cols = len(f.readline().split(","))
            f.seek(0)
            self.data = np.genfromtxt(
                f, names=True, delimiter=",", dtype=None, filling_values=np.nan, usecols=(range(0, num_cols))
            )

            print self.data
        # Defines x and y values
        self.x = self.data.dtype.names
        print self.x
        self.y = self.data.dtype.names
        # Populates combo boxes with header names
        self.xcombo.clear()
        self.xcombo.addItems(self.x)
        self.ycombo.clear()
        self.ycombo.addItems(self.y)

        # Clears Legend
        self.legend_definitions()

    """
        def Save_Stats(self):
            self.f = open(self.fname, 'rb')
            data = np.genfromtxt(self.f, skip_header=1)
            fname = QtGui.QFileDialog.getSaveFileName(self, 'Save File', 
               '*.csv')            
            output_text = np.column_stack((self.x,self.y))
            np.savetxt(str(fname),output_text,fmt ='%1.2f',delimiter=',', header = self.header)                        
"""

    def Plot_Function(self):
        self.legend.remove()
        # Takes x and y values to plot from combo box selection
        self.xval = self.data[self.data.dtype.names[self.xcombo.currentIndex()]]
        self.yval = self.data[self.data.dtype.names[self.ycombo.currentIndex()]]
        # self.yval = self.yval - np.median(self.yval)

        # Calculates stats info of y values
        self.stats()

        temp_scatter = self.mpl.canvas.ax.scatter(
            self.xval,
            self.yval,
            color=self.marker_colour.currentText(),
            marker=self.marker_style.currentText(),
            s=self.marker_size.value(),
        )
        self.handles.append(temp_scatter)
        self.labels.append(self.data.dtype.names[self.ycombo.currentIndex()])
        self.legend = self.mpl.canvas.fig.legend(self.handles, self.labels, "upper right")

        self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval)))
        self.mpl.canvas.ax.set_xlim(xmin=np.min(self.xval), xmax=np.max(self.xval))
        self.mpl.canvas.ax.set_autoscale_on(True)
        self.mpl.canvas.ax.autoscale_view(True, True, True)
        self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size=15)
        self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15)
        self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20)
        # self.mpl.canvas.ax.axis('auto')

        # Creates scatter plot

        self.mpl.canvas.draw()

    def legend_definitions(self):  # Handles legend
        self.handles = []
        self.labels = []

        # self.colors = itertools.cycle(["b","g","r","c","m","y","b"])
        # self.markers = itertools.cycle([".","D","p","*","+"])

        self.legend = self.mpl.canvas.fig.legend(self.handles, self.labels, "upper right")

    def stats(self):  # Calculates stats info of y values and sends back to UI
        self.min = str(np.round(np.min(self.yval), decimals=3))
        self.min_output.setText(self.min)
        self.max = str(np.round(np.max(self.yval), decimals=3))
        self.max_output.setText(self.max)
        self.mean = str(np.round(np.mean(self.yval), decimals=3))
        self.mean_output.setText(self.mean)
        self.median = str(np.round(np.median(self.yval), decimals=3))
        self.median_output.setText(self.median)
        self.sd = str(np.round(np.std(self.yval), decimals=3))
        self.sd_output.setText(self.sd)

    def moving_average_buttons(self):  # Radio Button Helper
        if self.rolling_mean_radio.isChecked():
            self.moving_mean()
        else:
            self.moving_median()

    def moving_mean(self):
        self.trend_y = rolling_mean(self.yval, self.moving_avg_window.value())
        self.plot_trendline()

    def moving_median(self):
        self.trend_y = rolling_median(self.yval, self.moving_avg_window.value())
        self.plot_trendline()

    def savgol_filter(self):
        self.trend_y = scipy.signal.savgol_filter(self.yval, self.savgol_window.value(), self.savgol_order.value())
        self.plot_trendline()

    def fit_manager(self):
        if self.data_trend.isChecked():
            self.fit_y = self.yval
            print self.fit_y
            self.polyfit()
            print "Data!"
        elif self.savgol_trend.isChecked():
            self.fit_y = self.trend_y = scipy.signal.savgol_filter(
                self.yval, self.savgol_window.value(), self.savgol_order.value()
            )
            print self.fit_y
            self.polyfit()
            print "Savgol!"

    def polyfit(self):  # Calculates Polynomial Fit with Error Estimation
        # Calculate Poly Fit
        self.order = self.poly_order.value()

        self.p = np.polyfit(self.xval, self.fit_y, self.order)  # coefficients
        self.trend_y = np.polyval(self.p, self.xval)  # fit values
        self.plot_trendline()

        """if self.data_trend.isChecked():
                self.p = np.polyfit(self.xval, self.yval, self.order)  #coefficients
                self.trend_y = np.polyval(self.p, self.xval) #fit values
                self.plot_trendline()
            
            if self.avg_trend.isChecked():
                self.rm_y= rolling_mean(self.yval, self.moving_avg_window.value())
                self.rm_y = np.ma.masked_invalid(self.rm_y)
                print np.shape(self.rm_y)
                print self.rm_y
                print np.shape(self.xval)
                self.p = np.polyfit(self.xval, self.rm_y, self.order)  #coefficients
                self.trend_y = np.polyval(self.p, self.xval) #fit values
                self.plot_trendline()"""

        # Calculate coeffecient of determination
        self.residuals = np.subtract(self.yval, self.trend_y)  # residuals
        self.RSS = np.sum(np.square(self.residuals))  # residual sum of squares
        self.TSS = np.sum(np.square(np.subtract(self.yval, np.mean(self.yval))))

        # Sends R-Squared value back to UI
        self.r_squared = str(np.round(np.subtract(1, np.divide(self.RSS, self.TSS)), decimals=3))  # send back to GUI
        self.r_squared_output.setText(self.r_squared)

        # Sends trendline equation back to UI
        coeff1 = np.round(self.p[0], decimals=10)
        coeff1 = str(coeff1)
        coeff2 = np.round(self.p[1], decimals=8)
        coeff2 = str(coeff2)
        if self.order == 1:
            self.fit_equation = coeff1 + "x + " + coeff2
            self.trendline_equation.setText(self.fit_equation)
        if self.order == 2:
            coeff3 = np.round(self.p[2], decimals=3)
            coeff3 = str(coeff3)
            self.fit_equation = coeff1 + "x^2 + " + coeff2 + "x + " + coeff3
            self.trendline_equation.setText(self.fit_equation)
        if self.order == 3:
            coeff3 = np.round(self.p[2], decimals=10)
            coeff3 = str(coeff3)
            coeff4 = np.round(self.p[3], decimals=3)
            coeff4 = str(coeff4)
            self.fit_equation = coeff1 + "x^3 + " + coeff2 + "x^2 + " + coeff3 + "x + " + coeff4
            self.trendline_equation.setText(self.fit_equation)

    def plot_histogram(self):
        self.ClearPlot()
        self.yval = self.data[self.data.dtype.names[self.ycombo.currentIndex()]]
        self.mpl.canvas.ax.hist(self.yval, self.bins.value())
        self.mpl.canvas.ax.set_xlabel("Value - mS/m", size=15)
        self.mpl.canvas.ax.set_ylabel("Frequency", size=15)
        self.mpl.canvas.ax.set_title(self.chart_title.text() + " Histogram. Bins = " + str(self.bins.value()), size=20)
        self.mpl.canvas.draw()

    def plot_trendline(self):  # Plots poly-line as solid line
        self.mpl.canvas.ax.plot(
            self.xval,
            self.trend_y,
            color=self.line_colour.currentText(),
            linestyle=self.line_style.currentText(),
            linewidth=self.line_width.value(),
        )
        self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval)))
        self.mpl.canvas.ax.set_autoscale_on(True)
        self.mpl.canvas.ax.autoscale_view(True, True, True)
        self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size=15)
        self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15)
        self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20)
        # self.mpl.canvas.ax.set_ylabel(self.ytitle, size = 15)
        # self.mpl.canvas.ax.set_title(self.title, size = 15)
        # self.handles.append(trendline)
        # self.handles.append(poly_line)
        # self.poly_order_title = self.poly_order.text()
        # self.labels.append(self.poly_order_title + ' Order Polynomial')
        # self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right')
        self.mpl.canvas.draw()

    def button_grid(self):  # Defines button and layout
        # self.firstrun=True
        self.buttons_layout = QtGui.QGridLayout()
        self.buttons_box = QtGui.QGroupBox()
        self.buttons_box.setLayout(self.buttons_layout)

        self.stats_layout = QtGui.QGridLayout()
        self.stats_box = QtGui.QGroupBox()
        self.stats_box.setLayout(self.stats_layout)

        self.plot_layout = QtGui.QGridLayout()
        self.plot_box = QtGui.QGroupBox()
        self.plot_box.setLayout(self.plot_layout)

        self.curvefit_layout = QtGui.QGridLayout()
        self.curvefit_box = QtGui.QGroupBox()
        self.curvefit_box.setLayout(self.curvefit_layout)

        # File Properties
        self.Grid_horizontal_Layout_2.addWidget(self.buttons_box, 1)
        string = '<span style=" font-size:10pt;; font-weight:600;">File Settings</span>'
        self.buttons_layout_text = QtGui.QLabel(string, self)

        self.buttons = QtGui.QButtonGroup()
        self.open_button = QtGui.QPushButton("Open", self)
        self.buttons.addButton(self.open_button)
        self.open_button.clicked.connect(self.Open_File)
        self.plot_button = QtGui.QPushButton("Plot", self)
        self.buttons.addButton(self.plot_button)
        self.plot_button.clicked.connect(self.Plot_Function)
        self.clear_button = QtGui.QPushButton("Clear", self)
        self.buttons.addButton(self.clear_button)
        self.clear_button.clicked.connect(self.ClearPlot)
        self.chart_title = QtGui.QLineEdit(self)
        self.chart_title.setText("Enter Chart Title")

        self.xcombo = QtGui.QComboBox()
        self.xcombo.addItems("X")
        self.x_lbl = QtGui.QLabel("X Values --")

        self.ycombo = QtGui.QComboBox()
        self.ycombo.addItems("Y")
        self.y_lbl = QtGui.QLabel("Y values --")

        self.x_units = QtGui.QLineEdit(self)
        self.x_units_lbl = QtGui.QLabel("Input X Units:", self)
        # self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog)
        self.y_units = QtGui.QLineEdit(self)
        self.y_units_lbl = QtGui.QLabel("Input Y Units:", self)

        self.buttons_layout.addWidget(self.buttons_layout_text, 0, 0, 1, 4)
        self.buttons_layout.addWidget(self.open_button, 1, 0)
        self.buttons_layout.addWidget(self.plot_button, 2, 0)
        self.buttons_layout.addWidget(self.clear_button, 3, 0)
        self.buttons_layout.addWidget(self.chart_title, 4, 0)
        self.buttons_layout.addWidget(self.x_lbl, 1, 1)
        self.buttons_layout.addWidget(self.xcombo, 2, 1)
        self.buttons_layout.addWidget(self.y_lbl, 3, 1)
        self.buttons_layout.addWidget(self.ycombo, 4, 1)
        self.buttons_layout.addWidget(self.x_units_lbl, 1, 3)
        self.buttons_layout.addWidget(self.x_units, 2, 3)
        self.buttons_layout.addWidget(self.y_units_lbl, 3, 3)
        self.buttons_layout.addWidget(self.y_units, 4, 3)

        # Plotting Properties
        self.Grid_horizontal_Layout_2.addWidget(self.plot_box, 1)
        string = '<span style=" font-size:10pt;; font-weight:600;">Plot Settings</span>'
        self.plot_layout_text = QtGui.QLabel(string, self)
        self.plot_buttons = QtGui.QButtonGroup()

        self.marker_style = QtGui.QComboBox()
        self.marker_style.addItems((".", "o", "v", "^", "*", "D", "d"))
        self.marker_style_lbl = QtGui.QLabel("Marker Style", self)
        self.marker_colour = QtGui.QComboBox()
        self.marker_size_lbl = QtGui.QLabel("Marker Size", self)
        self.marker_size = QtGui.QSpinBox()
        self.marker_size.setRange(1, 1000)
        self.marker_size.setValue(30)
        self.marker_colour.addItems(("0.25", "0.5", "0.75", "k", "b", "g", "r", "c", "y", "m"))
        self.marker_colour_lbl = QtGui.QLabel("Marker Colour", self)

        self.line_style = QtGui.QComboBox()
        self.line_style.addItems(("-", "--", ":", "_"))
        self.line_style_lbl = QtGui.QLabel("Line Style", self)
        self.line_width = QtGui.QSpinBox()
        self.line_width.setRange(1, 10)
        self.line_width_lbl = QtGui.QLabel("Line Width", self)
        self.line_colour = QtGui.QComboBox()
        self.line_colour.addItems(("r", "b", "g", "c", "y", "m", "0.25", "0.5", "0.75", "k"))
        self.line_colour_lbl = QtGui.QLabel("Line Colour", self)

        self.plot_layout.addWidget(self.plot_layout_text, 0, 0, 1, 2)
        self.plot_layout.addWidget(self.line_style_lbl, 1, 0)
        self.plot_layout.addWidget(self.line_style, 1, 1)
        self.plot_layout.addWidget(self.line_width_lbl, 2, 0)
        self.plot_layout.addWidget(self.line_width, 2, 1)
        self.plot_layout.addWidget(self.line_colour_lbl, 3, 0)
        self.plot_layout.addWidget(self.line_colour, 3, 1)
        self.plot_layout.addWidget(self.marker_style_lbl, 4, 0)
        self.plot_layout.addWidget(self.marker_style, 4, 1)
        self.plot_layout.addWidget(self.marker_size_lbl, 5, 0)
        self.plot_layout.addWidget(self.marker_size, 5, 1)
        self.plot_layout.addWidget(self.marker_colour_lbl, 6, 0)
        self.plot_layout.addWidget(self.marker_colour, 6, 1)

        self.Grid_horizontal_Layout_2.addWidget(self.curvefit_box, 1)
        string = '<span style=" font-size:10pt;; font-weight:600;">Filtering/Fitting Settings</span>'
        self.curvefit_layout_text = QtGui.QLabel(string, self)
        self.curvefit_buttons = QtGui.QButtonGroup()

        self.curvefit_buttons = QtGui.QButtonGroup()
        self.poly_label = QtGui.QLabel("Poly Fit:")
        # self.poly_fit = QtGui.QRadioButton('Poly Fit', self)
        self.data_trend = QtGui.QRadioButton("Of Data:", self)
        self.savgol_trend = QtGui.QRadioButton("Filtered Data:", self)
        self.poly_order_text = QtGui.QLabel("Order", self)
        self.poly_order = QtGui.QSpinBox(self)
        self.poly_order.setRange(1, 10)
        self.poly_plot_button = QtGui.QPushButton("Plot", self)
        self.curvefit_buttons.addButton(self.poly_plot_button)
        self.poly_plot_button.clicked.connect(self.fit_manager)

        self.rolling_mean_radio = QtGui.QRadioButton("Rolling Mean", self)
        self.rolling_median_radio = QtGui.QRadioButton("Rolling Median", self)
        self.moving_avg_window_text = QtGui.QLabel("Window")
        self.moving_avg_window = QtGui.QSpinBox(self)
        self.moving_avg_window.setRange(1, 1000)
        self.moving_avg_plot = QtGui.QPushButton("Plot", self)
        self.moving_avg_plot.clicked.connect(self.moving_average_buttons)

        self.savgol_lbl = QtGui.QLabel("Savgol-Golay Filter: ", self)
        self.savgol_window_lbl = QtGui.QLabel("Window Length", self)
        self.savgol_window = QtGui.QSpinBox(self)
        self.savgol_window.setRange(1, 100)
        self.savgol_window.setValue(5)
        self.savgol_order_lbl = QtGui.QLabel("Poly Order", self)
        self.savgol_order = QtGui.QSpinBox(self)
        self.savgol_order.setRange(-4, 4)
        self.savgol_order.setValue(2)
        self.savgol_plot = QtGui.QPushButton("Plot", self)
        self.savgol_plot.clicked.connect(self.savgol_filter)

        self.trendline_lbl = QtGui.QLabel("Trendline Equation")
        self.trendline_equation = QtGui.QLineEdit(self)
        self.r_squared_lbl = QtGui.QLabel("R Squared")
        self.r_squared_output = QtGui.QLineEdit(self)

        self.curvefit_layout.addWidget(self.curvefit_layout_text, 0, 0, 1, 4)
        self.curvefit_layout.addWidget(self.poly_label, 1, 0)
        self.curvefit_layout.addWidget(self.data_trend, 1, 1)
        self.curvefit_layout.addWidget(self.savgol_trend, 1, 2)
        self.curvefit_layout.addWidget(self.poly_order_text, 1, 3)
        self.curvefit_layout.addWidget(self.poly_order, 1, 4)
        self.curvefit_layout.addWidget(self.poly_plot_button, 1, 5)
        self.curvefit_layout.addWidget(self.rolling_mean_radio, 2, 0)
        self.curvefit_layout.addWidget(self.rolling_median_radio, 2, 1)
        self.curvefit_layout.addWidget(self.moving_avg_window_text, 2, 2)
        self.curvefit_layout.addWidget(self.moving_avg_window, 2, 3)
        self.curvefit_layout.addWidget(self.moving_avg_plot, 2, 4)
        self.curvefit_layout.addWidget(self.savgol_lbl, 3, 0)
        self.curvefit_layout.addWidget(self.savgol_window_lbl, 3, 1)
        self.curvefit_layout.addWidget(self.savgol_window, 3, 2)
        self.curvefit_layout.addWidget(self.savgol_order_lbl, 3, 3)
        self.curvefit_layout.addWidget(self.savgol_order, 3, 4)
        self.curvefit_layout.addWidget(self.savgol_plot, 3, 5)
        self.curvefit_layout.addWidget(self.trendline_lbl, 4, 0)
        self.curvefit_layout.addWidget(self.trendline_equation, 4, 1)
        self.curvefit_layout.addWidget(self.r_squared_lbl, 4, 2)
        self.curvefit_layout.addWidget(self.r_squared_output, 4, 3)

        # Stats Properties
        self.Grid_horizontal_Layout_2.addWidget(self.stats_box, 1)
        string = '<span style=" font-size:10pt;; font-weight:600;">Stats</span>'
        self.stats_layout_text = QtGui.QLabel(string, self)

        self.min_output_lbl = QtGui.QLabel("Data Min:")
        self.min_output = QtGui.QLineEdit(self)

        self.max_output_lbl = QtGui.QLabel("Data Max:")
        self.max_output = QtGui.QLineEdit(self)

        self.mean_output_lbl = QtGui.QLabel("Data Mean:")
        self.mean_output = QtGui.QLineEdit(self)

        self.median_output_lbl = QtGui.QLabel("Data Median:")
        self.median_output = QtGui.QLineEdit(self)

        self.sd_lbl = QtGui.QLabel("Std Deviation:")
        self.sd_output = QtGui.QLineEdit(self)

        self.bins_lbl = QtGui.QLabel("Histogram Bins:")
        self.bins = QtGui.QSpinBox(self)
        self.bins.setRange(1, 1000)
        self.bins.setValue(50)
        self.histogram = QtGui.QPushButton("Plot", self)
        self.histogram.clicked.connect(self.plot_histogram)

        self.stats_layout.addWidget(self.stats_layout_text, 0, 0, 1, 4)
        self.stats_layout.addWidget(self.min_output_lbl, 1, 0)
        self.stats_layout.addWidget(self.min_output, 1, 1)
        self.stats_layout.addWidget(self.max_output_lbl, 2, 0)
        self.stats_layout.addWidget(self.max_output, 2, 1)
        self.stats_layout.addWidget(self.mean_output_lbl, 3, 0)
        self.stats_layout.addWidget(self.mean_output, 3, 1)
        self.stats_layout.addWidget(self.median_output_lbl, 4, 0)
        self.stats_layout.addWidget(self.median_output, 4, 1)
        self.stats_layout.addWidget(self.sd_lbl, 5, 0)
        self.stats_layout.addWidget(self.sd_output, 5, 1)
        self.stats_layout.addWidget(self.bins_lbl, 6, 0)
        self.stats_layout.addWidget(self.bins, 6, 1)
        self.stats_layout.addWidget(self.histogram, 6, 2)

    def __init__(self, parent=None):
        # initialization of the superclass
        super(ArchaeoPYMainWindow, self).__init__(parent)
        # setup the GUI --> function generated by pyuic4
        self.setupUi(self)
        # Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
        self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
        self.navi_toolbar.clear()

        # Adds Buttons
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("home.png"), "Home", self.navi_toolbar.home)
        # a.setToolTip('returns axes to original position')
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("move.png"), "Pan", self.navi_toolbar.pan)
        a.setToolTip("Pan axes with left mouse, zoom with right")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("zoom_to_rect.png"), "Zoom", self.navi_toolbar.zoom)
        a.setToolTip("Zoom to Rectangle")
        a = self.navi_toolbar.addAction(self.navi_toolbar._icon("filesave.png"), "Save", self.navi_toolbar.save_figure)
        a.setToolTip("Save the figure")

        QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard)

        # self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label')

        # Button_layout is a QT desginer Grid Layout.
        self.toolbar_grid.addWidget(self.navi_toolbar)
        self.button_grid()
Example #58
0
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow):

        
        """Customization for Qt Designer created window"""
    
        def ClearPlot(self):
            self.mpl.canvas.ax.clear()
            self.mpl.canvas.draw()
            #Clears Legend
            self.legend.remove()
            self.legend_definitions()
            self.mpl.canvas.draw()
            
            
        def copy_to_clipboard(self):
            pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas)
            QtGui.QApplication.clipboard().setPixmap(pixmap)
        
        def Open_File(self):
            self.fname = QtGui.QFileDialog.getOpenFileName()
            #Opes File
            with open(self.fname, 'r') as f:
                num_cols = len(f.readline().split('	'))-1
                f.seek(0)
                self.data = np.genfromtxt(f, names=True, delimiter='	',dtype=None,filling_values = np.nan, usecols=(range(0,num_cols)))

            self.open_handler()


        def open_handler(self):
            if self.plot1_selector.isChecked():
                #Defines x and y values
                self.x1 = self.data.dtype.names
                self.y1 = self.data.dtype.names
                #Populates combo boxes with header names
                self.x1combo.clear()
                self.x1combo.addItems(self.x1)
                self.y1combo.clear()
                self.y1combo.addItems(self.y1)

            if self.plot2_selector.isChecked():
                #Defines x and y values
                self.x2 = self.data.dtype.names
                self.y2 = self.data.dtype.names
                #Populates combo boxes with header names
                self.x2combo.clear()
                self.x2combo.addItems(self.x2)
                self.y2combo.clear()
                self.y2combo.addItems(self.y2)

            if self.plot3_selector.isChecked():
                #Defines x and y values
                self.x3 = self.data.dtype.names
                self.y3 = self.data.dtype.names
                #Populates combo boxes with header names
                self.x3combo.clear()
                self.x3combo.addItems(self.x3)
                self.y3combo.clear()
                self.y3combo.addItems(self.y3)                        

            
        def Plot_Function(self):
            #self.mpl.canvas.fig.clear()
            #self.legend.remove()
            #Takes x and y values to plot from combo box selection
            self.x1val = self.data[self.data.dtype.names[self.x1combo.currentIndex()]]
            self.y1val = self.data[self.data.dtype.names[self.y1combo.currentIndex()]]
            self.x2val = self.data[self.data.dtype.names[self.x2combo.currentIndex()]]
            self.y2val = self.data[self.data.dtype.names[self.y2combo.currentIndex()]]
            self.x3val = self.data[self.data.dtype.names[self.x3combo.currentIndex()]]
            self.y3val = self.data[self.data.dtype.names[self.y3combo.currentIndex()]]            
            #self.yval = self.yval - np.median(self.yval)
            
            self.axes = self.canvas.fig.add_subplot

            self.plot1 = self.mpl.canvas.fig.add_subplot(3,1,1)
            self.plot2 = self.mpl.canvas.fig.add_subplot(3,1,2)
            self.plot3 = self.mpl.canvas.fig.add_subplot(3,1,3)            
            
            
            #Calculates stats info of y values
            #self.stats() 
         
            #self.plot1 = self.mpl.canvas.fig.add_subplot(3,1,1)
            #self.plot1.set_xlabel(self.x_units.text())
            #self.plot1.set_ylabel(self.y1_units.text(), size=15)
            self.plot1.axes.set_autoscale_on(True)
            self.plot1.axes.autoscale_view(True,True,True)
            self.plot1.plot(self.x1val,self.y1val)
            
            #self.plot2 = self.mpl.canvas.fig.add_subplot(3,1,2, sharex=self.plot1)
            #self.plot2.set_xlabel(self.x_units.text())
            #self.plot2.set_ylabel(self.y2_units.text(), size=15)
            self.plot2.plot(self.x2val,self.y2val)
            
            #self.plot3 = self.mpl.canvas.fig.add_subplot(3,1,3, sharex=self.plot1)
            #self.plot3.set_xlabel(self.x_units.text())
            #self.plot3.set_ylabel(self.y3_units.text(),size=15)
            self.plot3.plot(self.x3val, self.y3val)
            

            #temp_scatter = self.mpl.canvas.ax.scatter(self.xval,self.yval, color=self.marker_colour.currentText(),marker=self.marker_style.currentText())
            #self.handles.append(temp_scatter)
            #self.labels.append(self.data.dtype.names[self.ycombo.currentIndex()])
            #self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right')
            
            #self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval)))
            #self.mpl.canvas.ax.set_xlim(xmin=np.min(self.xval), xmax=np.max(self.xval))            
            #self.mpl.canvas.ax.set_autoscale_on(True)
            #self.mpl.canvas.ax.autoscale_view(True,True,True)
            #self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size = 15)
            #self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15)
            #self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20)
            #self.mpl.canvas.ax.axis('auto')
            
            #Creates scatter plot

            #self.mpl.canvas.draw()
            
        
        def legend_definitions(self): #Handles legend
            self.handles = []
            self.labels = []
            
            #self.colors = itertools.cycle(["b","g","r","c","m","y","b"])
            #self.markers = itertools.cycle([".","D","p","*","+"])
            
            self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right')

        def stats(self): #Calculates stats info of y values and sends back to UI
            self.mean = str(np.round(np.mean(self.yval), decimals=3))
            self.mean_output.setText(self.mean)
            self.median = str(np.round(np.median(self.yval), decimals=3))
            self.median_output.setText(self.median)
            self.sd = str(np.round(np.std(self.yval), decimals=3))
            self.sd_output.setText(self.sd)
 
        def moving_average_buttons(self): #Radio Button Helper
            if self.rolling_mean_radio.isChecked():
                self.moving_mean()
            else:
                self.moving_median()
            
        def moving_mean(self):   
            self.trend_y= rolling_mean(self.yval, self.moving_avg_window.value())
            self.plot_trendline()
        
        def moving_median(self):
            self.trend_y = rolling_median(self.yval, self.moving_avg_window.value())
            self.plot_trendline()

                            
        def polyfit(self): #Calculates Polynomial Fit with Error Estimation
            #Calculate Poly Fit            
            self.order = self.poly_order.value()            
            self.p = np.polyfit(self.xval, self.yval, self.order)  #coefficients
            print self.order
            self.trend_y = np.polyval(self.p, self.xval) #fit values
            self.plot_trendline()
            
            #Calculate coeffecient of determination            
            self.residuals = np.subtract(self.yval, self.trend_y) #residuals
            self.RSS = np.sum(np.square(self.residuals)) #residual sum of squares
            self.TSS = np.sum(np.square(np.subtract(self.yval, np.mean(self.yval))))

            #Sends R-Squared value back to UI
            self.r_squared = str(np.round(np.subtract(1, np.divide(self.RSS, self.TSS)), decimals=3)) #send back to GUI
            self.r_squared_output.setText(self.r_squared) 

            #Sends trendline equation back to UI
            coeff1 = np.round(self.p[0], decimals=10)
            coeff1 = str(coeff1)
            coeff2 = np.round(self.p[1], decimals=8)
            coeff2 = str(coeff2)
            if self.order == 1:
                self.fit_equation = coeff1+'x + '+coeff2
                self.trendline_equation.setText(self.fit_equation) 
            if self.order == 2:
                coeff3 = np.round(self.p[2],decimals=3)
                coeff3 = str(coeff3)
                self.fit_equation = coeff1+'x^2 + '+coeff2+'x + '+coeff3
                self.trendline_equation.setText(self.fit_equation)
            if self.order == 3:
                coeff3 = np.round(self.p[2],decimals=5)
                coeff3 = str(coeff3)
                coeff4 = np.round(self.p[3],decimals=3)
                coeff4 = str(coeff4)
                self.fit_equation = coeff1+'x^3 + '+coeff2+'x^2 + '+coeff3+'x + '+coeff4
                self.trendline_equation.setText(self.fit_equation)    
            
                
        def plot_trendline(self): #Plots poly-line as solid line
            self.mpl.canvas.ax.plot(self.xval, self.trend_y, color=self.line_colour.currentText(), linestyle=self.line_style.currentText(), linewidth=self.line_width.value())            
            self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval)))
            self.mpl.canvas.ax.set_autoscale_on(True)
            self.mpl.canvas.ax.autoscale_view(True,True,True)
            self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size = 15)
            self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15)
            self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20)
            #self.mpl.canvas.ax.set_ylabel(self.ytitle, size = 15)
            #self.mpl.canvas.ax.set_title(self.title, size = 15)
            #self.handles.append(trendline)
            #self.handles.append(poly_line)
            #self.poly_order_title = self.poly_order.text()
            #self.labels.append(self.poly_order_title + ' Order Polynomial')
            #self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right')
            self.mpl.canvas.draw()
        
                              
        def button_grid(self): #Defines button and layout 
            #self.firstrun=True
            self.plot_layout = QtGui.QGridLayout()
            self.plot_box = QtGui.QGroupBox()
            self.plot_box.setLayout(self.plot_layout)

            #self.plot2_layout = QtGui.QGridLayout()
            #self.plot2_box = QtGui.QGroupBox()
            #self.plot2_box.setLayout(self.plot2_layout)

            #self.plot3_layout = QtGui.QGridLayout()
            #self.plot3_box = QtGui.QGroupBox()
            #self.plot3_box.setLayout(self.plot3_layout)
            
            #self.stats_layout = QtGui.QGridLayout()
            #self.stats_box = QtGui.QGroupBox()
            #self.stats_box.setLayout(self.stats_layout)

            #self.plot_layout = QtGui.QGridLayout()
            #self.plot_box = QtGui.QGroupBox()
            #self.plot_box.setLayout(self.plot_layout)
            
            #File-Plot Options
            self.Grid_horizontal_Layout_2.addWidget(self.plot_box, 1)
            string = '<span style=" font-size:12pt;; font-weight:600;">File Options</span>'       
            self.plot_layout_text = QtGui.QLabel(string, self)             
            
            self.plot_buttons = QtGui.QButtonGroup()            
            self.open_button = QtGui.QPushButton('Open', self)
            self.plot_buttons.addButton(self.open_button)
            self.open_button.clicked.connect(self.Open_File)
            self.plot_button = QtGui.QPushButton('Plot', self)
            self.plot_buttons.addButton(self.plot_button)
            self.plot_button.clicked.connect(self.Plot_Function)
            self.clear_button = QtGui.QPushButton('Clear', self)
            self.plot_buttons.addButton(self.clear_button)
            self.clear_button.clicked.connect(self.ClearPlot)
            self.chart_title = QtGui.QLineEdit(self)
            self.chart_title.setText("Enter Chart Title")
            
            self.plot1_selector = QtGui.QRadioButton('Plot 1', self)
            self.plot2_selector = QtGui.QRadioButton('Plot 2', self)
            self.plot3_selector = QtGui.QRadioButton('Plot 3', self)
            
            
            self.x1combo = QtGui.QComboBox()
            self.x1combo.addItems('X')
            self.x1_lbl = QtGui.QLabel('Plot 1: X Values --')          
            
            self.y1combo = QtGui.QComboBox()
            self.y1combo.addItems('Y')
            self.y1_lbl = QtGui.QLabel('Plot 1: Y values --')

            self.x1_units = QtGui.QLineEdit(self)
            self.x1_units_lbl = QtGui.QLabel("X Units:", self)
            #self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog)
            self.y1_units = QtGui.QLineEdit(self)
            self.y1_units_lbl = QtGui.QLabel("Y Units:", self)
            
            self.x2combo = QtGui.QComboBox()
            self.x2combo.addItems('X')
            self.x2_lbl = QtGui.QLabel('Plot 2 X Values --')          
            
            self.y2combo = QtGui.QComboBox()
            self.y2combo.addItems('Y')
            self.y2_lbl = QtGui.QLabel('Plot 2 Y values --')

            self.x2_units = QtGui.QLineEdit(self)
            self.x2_units_lbl = QtGui.QLabel("X Units:", self)
            #self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog)
            self.y2_units = QtGui.QLineEdit(self)
            self.y2_units_lbl = QtGui.QLabel("Y Units:", self)
            
            self.x3combo = QtGui.QComboBox()
            self.x3combo.addItems('X')
            self.x3_lbl = QtGui.QLabel('Plot 3 X Values --')          
            
            self.y3combo = QtGui.QComboBox()
            self.y3combo.addItems('Y')
            self.y3_lbl = QtGui.QLabel('Plot 3 Y values --')

            self.x3_units = QtGui.QLineEdit(self)
            self.x3_units_lbl = QtGui.QLabel("X Units:", self)
            #self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog)
            self.y3_units = QtGui.QLineEdit(self)
            self.y3_units_lbl = QtGui.QLabel("Y Units:", self)

            self.plot_layout.addWidget(self.plot_layout_text, 0,0,1,4)                      
            self.plot_layout.addWidget(self.plot1_selector, 1,0)
            self.plot_layout.addWidget(self.plot2_selector, 2,0)
            self.plot_layout.addWidget(self.plot3_selector, 3,0)            
            self.plot_layout.addWidget(self.open_button, 1,1)
            self.plot_layout.addWidget(self.plot_button, 2,1)
            self.plot_layout.addWidget(self.clear_button, 3,1)
            self.plot_layout.addWidget(self.chart_title, 4,1)
            self.plot_layout.addWidget(self.x1_lbl, 1,2)
            self.plot_layout.addWidget(self.x1combo, 2,2)
            self.plot_layout.addWidget(self.y1_lbl, 3,2)
            self.plot_layout.addWidget(self.y1combo, 4,2)
            self.plot_layout.addWidget(self.x1_units_lbl, 1,3)
            self.plot_layout.addWidget(self.x1_units, 2,3)            
            self.plot_layout.addWidget(self.y1_units_lbl, 3,3)            
            self.plot_layout.addWidget(self.y1_units, 4,3)
            self.plot_layout.addWidget(self.x2_lbl, 1,4)
            self.plot_layout.addWidget(self.x2combo, 2,4)
            self.plot_layout.addWidget(self.y2_lbl, 3,4)
            self.plot_layout.addWidget(self.y2combo, 4,4)
            self.plot_layout.addWidget(self.x2_units_lbl, 1,5)
            self.plot_layout.addWidget(self.x2_units, 2,5)            
            self.plot_layout.addWidget(self.y2_units_lbl, 3,5)            
            self.plot_layout.addWidget(self.y2_units, 4,5)
            self.plot_layout.addWidget(self.x3_lbl, 1,6)
            self.plot_layout.addWidget(self.x3combo, 2,6)
            self.plot_layout.addWidget(self.y3_lbl, 3,6)
            self.plot_layout.addWidget(self.y3combo, 4,6)
            self.plot_layout.addWidget(self.x3_units_lbl, 1,7)
            self.plot_layout.addWidget(self.x3_units, 2,7)            
            self.plot_layout.addWidget(self.y3_units_lbl, 3,7)            
            self.plot_layout.addWidget(self.y3_units, 4,7)

            #Plotting Properties
            '''self.Grid_horizontal_Layout_2.addWidget(self.plot_box, 1)
            string = '<span style=" font-size:12pt;; font-weight:600;">Plot Settings</span>'       
            self.plot_layout_text = QtGui.QLabel(string, self)
            self.plot_buttons = QtGui.QButtonGroup()
                        
            self.marker_style = QtGui.QComboBox()
            self.marker_style.addItems(('.', 'o', 'v', '^', '*', 'D', 'd'))
            self.marker_style_lbl = QtGui.QLabel('Marker Style', self)
            self.marker_colour = QtGui.QComboBox()
            self.marker_colour.addItems(('0.25', '0.5', '0.75', 'k', 'b', 'g', 'r', 'c', 'y', 'm'))
            self.marker_colour_lbl = QtGui.QLabel('Marker Colour', self)
             
            self.line_style = QtGui.QComboBox()
            self.line_style.addItems(('-', '--', ':','_'))
            self.line_style_lbl = QtGui.QLabel('Line Style', self)
            self.line_width = QtGui.QSpinBox()
            self.line_width.setRange(1,10)
            self.line_width_lbl = QtGui.QLabel('Line Width', self)
            self.line_colour = QtGui.QComboBox()
            self.line_colour.addItems(('r','b','g','c','y','m','0.25','0.5','0.75','k'))
            self.line_colour_lbl = QtGui.QLabel('Line Colour', self)
        
            self.plot_layout.addWidget(self.plot_layout_text, 0,0,1,4)
            self.plot_layout.addWidget(self.line_style_lbl, 1,0)
            self.plot_layout.addWidget(self.line_style, 1,1)
            self.plot_layout.addWidget(self.line_width_lbl, 2,0)
            self.plot_layout.addWidget(self.line_width, 2,1)
            self.plot_layout.addWidget(self.line_colour_lbl, 3,0)
            self.plot_layout.addWidget(self.line_colour,3,1)              
            self.plot_layout.addWidget(self.marker_style_lbl, 1,2)
            self.plot_layout.addWidget(self.marker_style, 1,3)
            self.plot_layout.addWidget(self.marker_colour_lbl, 2,2)
            self.plot_layout.addWidget(self.marker_colour, 2,3)
            

            #Stats Properties
            self.Grid_horizontal_Layout_2.addWidget(self.stats_box, 1)
            string = '<span style=" font-size:12pt;; font-weight:600;">Stats Settings</span>'       
            self.stats_layout_text = QtGui.QLabel(string, self)
            
            self.mean_output_lbl = QtGui.QLabel("Data Mean")            
            self.mean_output = QtGui.QLineEdit(self)
            
            self.median_output_lbl = QtGui.QLabel("Data Median")
            self.median_output = QtGui.QLineEdit(self)
            
            self.sd_lbl = QtGui.QLabel("Std Deviation")
            self.sd_output = QtGui.QLineEdit(self)
           
            self.stats_buttons = QtGui.QButtonGroup()            
            self.poly_label = QtGui.QLabel('Poly Fit')            
            #self.poly_fit = QtGui.QRadioButton('Poly Fit', self)            
            self.poly_order_text = QtGui.QLabel('Order', self)
            self.poly_order = QtGui.QSpinBox(self)
            self.poly_order.setRange(1, 10)  
            self.poly_plot_button = QtGui.QPushButton('Plot', self)
            self.stats_buttons.addButton(self.poly_plot_button)
            self.poly_plot_button.clicked.connect(self.polyfit)
            
            self.rolling_mean_radio = QtGui.QRadioButton('Rolling Mean', self)
            self.rolling_median_radio = QtGui.QRadioButton('Rolling Median', self) 
            self.moving_avg_window_text = QtGui.QLabel('Window')
            self.moving_avg_window = QtGui.QSpinBox(self)
            self.moving_avg_window.setRange(1,1000)
            self.moving_avg_plot = QtGui.QPushButton('Plot', self)
            self.moving_avg_plot.clicked.connect(self.moving_average_buttons)

            self.trendline_lbl = QtGui.QLabel("Trendline Equation")
            self.trendline_equation = QtGui.QLineEdit(self)
            self.r_squared_lbl = QtGui.QLabel("R Squared")            
            self.r_squared_output = QtGui.QLineEdit(self)
            
            self.stats_layout.addWidget(self.stats_layout_text, 0,0,1,4)
            self.stats_layout.addWidget(self.mean_output_lbl, 1,0)
            self.stats_layout.addWidget(self.mean_output, 1,1)
            self.stats_layout.addWidget(self.median_output_lbl, 1,2)
            self.stats_layout.addWidget(self.median_output, 1,3)
            self.stats_layout.addWidget(self.sd_lbl, 1,4)
            self.stats_layout.addWidget(self.sd_output, 1,5)            
            self.stats_layout.addWidget(self.poly_label, 2,0)
            self.stats_layout.addWidget(self.poly_order_text, 2,1)
            self.stats_layout.addWidget(self.poly_order, 2,2)
            self.stats_layout.addWidget(self.poly_plot_button,2,3)
            self.stats_layout.addWidget(self.rolling_mean_radio, 3,0)
            self.stats_layout.addWidget(self.rolling_median_radio, 3,1)
            self.stats_layout.addWidget(self.moving_avg_window_text,3,2)
            self.stats_layout.addWidget(self.moving_avg_window, 3,3)
            self.stats_layout.addWidget(self.moving_avg_plot, 3,4)
            self.stats_layout.addWidget(self.trendline_lbl, 5,0)
            self.stats_layout.addWidget(self.trendline_equation, 5,1)
            self.stats_layout.addWidget(self.r_squared_lbl, 5,2)
            self.stats_layout.addWidget(self.r_squared_output, 5,3)'''

            
                    
        def __init__(self, parent = None):
            # initialization of the superclass
            super(ArchaeoPYMainWindow, self).__init__(parent)
            # setup the GUI --> function generated by pyuic4
            self.setupUi(self)
            #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
            self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
            self.navi_toolbar.clear()
    
        #Adds Buttons
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home',
                                            self.navi_toolbar.home)
            #a.setToolTip('returns axes to original position')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan',
                                            self.navi_toolbar.pan)
            a.setToolTip('Pan axes with left mouse, zoom with right')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
                                            self.navi_toolbar.zoom)
            a.setToolTip('Zoom to Rectangle')
            a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save',
                               self.navi_toolbar.save_figure)
            a.setToolTip('Save the figure')
            
            QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard)

            
            #self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label')
            
            #Button_layout is a QT desginer Grid Layout.
            self.toolbar_grid.addWidget(self.navi_toolbar)
            self.button_grid()