Beispiel #1
0
class slicePanel(wx.Panel):
    '''
    This is the 1D plot panel which displays the slices which the user selects
    '''
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)

        self.sliceFigure = Figure(frameon=True, figsize=(2, 3))
        self.sliceFigure.set_facecolor('.82')
        self.sliceCanvas = FigureCanvas(self, -1, self.sliceFigure)
        self.sliceCanvas.SetAutoLayout(False)

        self.box = Toolbar(self.sliceCanvas)
        self.box.Hide()
        self.box.zoom()

        self.fm = FigureManagerBase(self.sliceCanvas, 1)
        _pylab_helpers.Gcf.set_active(self.fm)

        self.sliceAxis = self.sliceFigure.add_axes([0.1, 0.2, 0.8, 0.7])

        sliceSizer = wx.BoxSizer(wx.VERTICAL)
        sliceSizer.Add(self.sliceCanvas,
                       1,
                       wx.EXPAND | wx.RIGHT | wx.LEFT,
                       border=1)
        self.SetSizer(sliceSizer)
        return

    def updatePlot(self, data, xaxis, legLab, xlabel, ylabel, title, scale,
                   legTog):
        '''
        The user can select a new slice at any time to plot on the 1D panel.
        This method refreshes the plot so that the new data is displayed.
        '''
        self.sliceAxis.cla()

        self.linePlot = self.sliceAxis.plot(xaxis, (array(data).T))
        xlim((min(xaxis), max(xaxis)))

        self.sliceAxis.leg = legend(legLab)

        self.sliceAxis.leg.set_visible(legTog)

        self.sliceAxis.set_xlabel(xlabel)
        self.sliceAxis.set_ylabel(ylabel)
        self.sliceAxis.set_title(title)

        self.sliceAxis.set_yscale(str(scale))

        draw()

        return
Beispiel #2
0
class slicePanel(wx.Panel):
    '''
    This is the 1D plot panel which displays the slices which the user selects
    '''

    def __init__(self,parent):
        wx.Panel.__init__(self,parent,style = wx.BORDER_SUNKEN)

        self.sliceFigure = Figure(frameon = True,figsize =(2,3))
        self.sliceFigure.set_facecolor('.82')
        self.sliceCanvas = FigureCanvas(self, -1, self.sliceFigure)
        self.sliceCanvas.SetAutoLayout(False)

        self.box = Toolbar(self.sliceCanvas)
        self.box.Hide()
        self.box.zoom()

        self.fm = FigureManagerBase(self.sliceCanvas, 1)
        _pylab_helpers.Gcf.set_active(self.fm)

        self.sliceAxis = self.sliceFigure.add_axes([0.1,0.2,0.8,0.7])

        sliceSizer = wx.BoxSizer(wx.VERTICAL)
        sliceSizer.Add(self.sliceCanvas,1,wx.EXPAND|wx.RIGHT|wx.LEFT,
                                                                    border = 1)
        self.SetSizer(sliceSizer)
        return

    def updatePlot(self,data,xaxis,legLab,xlabel,ylabel,title,scale,legTog):
        '''
        The user can select a new slice at any time to plot on the 1D panel.
        This method refreshes the plot so that the new data is displayed.
        '''
        self.sliceAxis.cla()

        self.linePlot = self.sliceAxis.plot(xaxis,(array(data).T))
        xlim((min(xaxis),max(xaxis)))

        self.sliceAxis.leg = legend(legLab)

        self.sliceAxis.leg.set_visible(legTog)

        self.sliceAxis.set_xlabel(xlabel)
        self.sliceAxis.set_ylabel(ylabel)
        self.sliceAxis.set_title(title)

        self.sliceAxis.set_yscale(str(scale))

        draw()

        return
Beispiel #3
0
class Plot(wx.Panel):
    def __init__(self, parent, id=-1, dpi=None, **kwargs):
        wx.Panel.__init__(self, parent, id=id, **kwargs)

        self.figure = mpl.figure.Figure(dpi=dpi, figsize=(12, 10))
        self.canvas = Canvas(self, -1, self.figure)

        self.l0 = wx.StaticText(self, -1, "Start at x=")
        self.t0 = wx.TextCtrl(self, 3, style=wx.TE_PROCESS_ENTER)
        #self.t0.SetRange(-1e10, 1e10)
        self.t0.Bind(wx.EVT_TEXT_ENTER, self.onUpdateT0, id=3)
        self.lv = wx.StaticText(self, -1, "")

        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()

        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer1.Add(self.l0)
        sizer1.Add(self.t0)
        sizer1.Add(self.lv)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizer1, 1, wx.EXPAND)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)

    def setLV(self, lv, lvm):
        self.lv.SetLabel(", last value = %g (mean %g)" % (lv, lvm))

    def onUpdateT0(self, event):
        x0 = float(self.t0.GetValue())
        self.figure.gca().set_xlim(left=x0)
        self.canvas.draw()
Beispiel #4
0
    def __init__(self, parent, id=-1, dpi=None, **kwargs):
        wx.Panel.__init__(self, parent, id=id, **kwargs)

        self.figure = mpl.figure.Figure(dpi=dpi, figsize=(12, 10))
        self.canvas = Canvas(self, -1, self.figure)

        self.l0 = wx.StaticText(self, -1, "Start at x=")
        self.t0 = wx.TextCtrl(self, 3, style=wx.TE_PROCESS_ENTER)
        #self.t0.SetRange(-1e10, 1e10)
        self.t0.Bind(wx.EVT_TEXT_ENTER, self.onUpdateT0, id=3)
        self.lv = wx.StaticText(self, -1, "")

        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()

        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer1.Add(self.l0)
        sizer1.Add(self.t0)
        sizer1.Add(self.lv)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizer1, 1, wx.EXPAND)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)
 def _init_toolbar(self, *args):
     NavigationToolbar2Wx._init_toolbar(self, *args)
     self.AddSimpleTool(_NTB_PLAY, _load_bitmap('forward.xpm'),
                        'Play', 'Start playing')
     self.AddSimpleTool(_NTB_LEFT, _load_bitmap('stock_left.xpm'),
                        'Left', 'Jump one screen to the left')
     self.AddSimpleTool(_NTB_RIGHT, _load_bitmap('stock_right.xpm'),
                        'Right', 'Jump one screen to the right')
     self.AddSimpleTool(_NTB_DOWN, _load_bitmap('stock_down.xpm'),
                        'Down', 'Go down one channel')
     self.AddSimpleTool(_NTB_UP, _load_bitmap('stock_up.xpm'),
                        'Up', 'Go up one channel')
     self.Bind(EVT_REDRAW, self._on_redraw)
     bind(self, wx.EVT_TOOL, self._on_play, id=_NTB_PLAY)
     bind(self, wx.EVT_TOOL, self._on_left, id=_NTB_LEFT)
     bind(self, wx.EVT_TOOL, self._on_right, id=_NTB_RIGHT)
     bind(self, wx.EVT_TOOL, self._on_down, id=_NTB_DOWN)
     bind(self, wx.EVT_TOOL, self._on_up, id=_NTB_UP)
Beispiel #6
0
    def __init__(self, *args, **kw):
        wx.Panel.__init__(self, *args, **kw)

        figure = Figure(figsize=(1, 1), dpi=72)
        canvas = FigureCanvas(self, wx.ID_ANY, figure)
        self.pylab_figure = PylabFigure(canvas)

        # Instantiate the matplotlib navigation toolbar and explicitly show it.
        mpl_toolbar = Toolbar(canvas)
        mpl_toolbar.Realize()

        # Create a vertical box sizer to manage the widgets in the main panel.
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(canvas, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, border=0)
        sizer.Add(mpl_toolbar, 0, wx.EXPAND | wx.ALL, border=0)

        # Associate the sizer with its container.
        self.SetSizer(sizer)
        sizer.Fit(self)
 def __init__(self, parent, id = -1, dpi = None, **kwargs):
     wx.Panel.__init__(self, parent, id=id, **kwargs)
     self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2,2))
     self.canvas = Canvas(self, -1, self.figure)
     self.toolbar = Toolbar(self.canvas)
     self.toolbar.Realize()
     sizer = wx.BoxSizer(wx.VERTICAL)
     sizer.Add(self.canvas,1,wx.EXPAND)
     sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
     self.SetSizer(sizer)
Beispiel #8
0
    def draw_empty(self):
        self.canvas.Destroy()
        self.toolbar.Destroy()
        plt = plot.Plot()

        self.canvas = FigureCanvas(self, -1, plt.fig)
        self.toolbar = NavigationToolbar(self.canvas)

        self.sizer.Add(self.toolbar, 0, wx.EXPAND)
        self.sizer.Add(self.canvas, 1, wx.GROW)
        self.Layout()
Beispiel #9
0
    def __init__(self,parent):
        wx.Panel.__init__(self,parent,-1)
        self.fig = Figure(figsize=(2,2))
        self.canvas = FigCanvas(self,-1,self.fig)

        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)
     def __init__(self, parent, fig, id = -1, dpi = None, **kwargs):
         wx.Panel.__init__(self, parent, id=id, **kwargs)
         fig.set_figheight(2)
         fig.set_figwidth(2)
         self.canvas = Canvas(self, -1, fig)
         self.toolbar = Toolbar(self.canvas)
         self.toolbar.Realize()
 
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.canvas,1,wx.EXPAND)
         sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
         self.SetSizer(sizer)
Beispiel #11
0
    def __init__(self, parent, sitwViewFrame):
        wx.Panel.__init__(self, parent)
        
        self.sitwViewFrame = sitwViewFrame
        
        
        self.Height_Loc = 60
        self.iColWidth = 100
        self.iGraphicHeight = 60 * 24 + self.Height_Loc
        self.iGraphicWidth = self.iColWidth / 2 + 4 * self.iColWidth
        
        
        
        self.figure = Figure()
        #self.figure.patch.set_fc((.9, .9, .9))
        self.figure.patch.set_fc('white')
        self.strTitleTex = self.figure.suptitle('', fontsize = 16, color = 'darkgreen')
        
        self.axes = self.figure.add_subplot(111, axisbg = (.8, .8, .8))
        

        self.axes.set_xlim(0, self.iGraphicWidth)
        self.axes.set_ylim(0, self.iGraphicHeight)
        self.axes.xaxis.set_visible(False)
        #self.axes.yaxis.set_visible(False)

        
        self.majorLocator   = MultipleLocator(60)
        self.majorFormatter = FormatStrFormatter('%d')
        self.minorLocator   = MultipleLocator(15)

        
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.toolbar = NavigationToolbar(self.canvas)
        #self.toolbar.DeleteToolByPos(0) #home
        #self.toolbar.DeleteToolByPos(0) #backward
        #self.toolbar.DeleteToolByPos(0) #forward
        self.toolbar.DeleteToolByPos(7) #subplots
        

        #toolitems = [t for t in NavigationToolbar.toolitems]        
        ##if t[0] in ('Home', 'Pan', 'Zoom', 'Save')]    
        #print 'toolitems', toolitems   
        #print self.toolbar.GetToolsCount(), '###'
        
        
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.sizer.Add(self.toolbar, 0, wx.EXPAND)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        
        self.SetSizer(self.sizer)
        self.Fit()
Beispiel #12
0
    def __init__(self, parent, figure, id=-1, **kwargs):
        wx.Panel.__init__(self, parent, id=id, **kwargs)
        
        self.figure = figure
        
        self.canvas = Canvas(self, -1, self.figure)
        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas,1,wx.EXPAND)
        sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)
Beispiel #13
0
 def add_toolbar(self):
     """Creates the matplotlib toolbar (zoom, pan/scroll, etc.)
     for the plot"""
     self.toolbar = NavigationToolbar2Wx(self.canvas)
     self.toolbar.Realize()
     if wx.Platform == '__WXMAC__':
         self.SetToolBar(self.toolbar)
     else:
         tw, th = self.toolbar.GetSizeTuple()
         fw, fh = self.canvas.GetSizeTuple()
         self.toolbar.SetSize(wx.Size(fw, th))
         self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND, 0)
     self.toolbar.update()
Beispiel #14
0
    def __init__(self, *args, **kw):
        wx.Panel.__init__(self, *args, **kw)

        # Instantiate a figure object that will contain our plots.
        figure = Figure(figsize=(1, 1), dpi=72)

        # Initialize the figure canvas, mapping the figure object to the plot
        # engine backend.
        canvas = FigureCanvas(self, wx.ID_ANY, figure)

        # Wx-Pylab magic ...
        # Make our canvas an active figure manager for pylab so that when
        # pylab plotting statements are executed they will operate on our
        # canvas and not create a new frame and canvas for display purposes.
        # This technique allows this application to execute code that uses
        # pylab stataments to generate plots and embed these plots in our
        # application window(s).  Use _activate_figure() to set.
        self.pylab_interface = EmbeddedPylab(canvas)

        # Instantiate the matplotlib navigation toolbar and explicitly show it.
        mpl_toolbar = Toolbar(canvas)
        mpl_toolbar.Realize()

        # Create a vertical box sizer to manage the widgets in the main panel.
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(canvas, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, border=0)
        sizer.Add(mpl_toolbar, 0, wx.EXPAND | wx.ALL, border=0)

        # Associate the sizer with its container.
        self.SetSizer(sizer)
        sizer.Fit(self)

        self.view = Probe.view

        self._need_redraw = False
        self.Bind(wx.EVT_SHOW, self.OnShow)
        self._calculating = False
        self.toolbar = mpl_toolbar
Beispiel #15
0
    def __init__(self, parent, id, data, minimum, maximum):
        self.id = id
        wx.Panel.__init__(self, parent, self.id, style=wx.SIMPLE_BORDER)
        self.data = data
        self.minimum = minimum
        self.maximum = maximum

        self.tooltip = wx.ToolTip(tip='Tip with a details of points')
        self.SetToolTip(self.tooltip)
        self.tooltip.Enable(True)
        self.tooltip.SetDelay(0)

        self.fig = plt.figure(self.id,
                              figsize=(12, 6.5),
                              dpi=100,
                              facecolor="w",
                              frameon=True)
        self.canvas = FigureCanvas(self, self.id, self.fig)
        self.toolbar = NavigationToolbar(self.canvas)
        mass_txt = wx.StaticText(self.toolbar,
                                 label='m/z',
                                 pos=(230, 7),
                                 size=(25, 17))
        mass_txt.SetBackgroundColour("light gray")
        self.mass = wx.TextCtrl(self.toolbar,
                                pos=(260, 4),
                                size=(50, 22),
                                style=wx.TE_READONLY)
        self.toolbar.SetToolBitmapSize(wx.Size(24, 25))
        self.toolbar.SetMinSize((1500, 40))
        self.toolbar.Realize()
        self.toolbar.Update()

        self.fig.canvas.mpl_connect('button_press_event', self.onclick)
        self.fig.canvas.mpl_connect('pick_event', self.on_pick)
        self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion)
        self.fig.canvas.mpl_connect('key_press_event', self.on_key)

        self.SetAutoLayout(True)
        self.SetBackgroundColour('midnight blue')
        # Now put all into a sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        # This way of adding to sizer allows resizing
        sizer.Add(self.canvas, 5, wx.LEFT | wx.TOP | wx.GROW)
        # Best to allow the toolbar to resize!
        sizer.Add(self.toolbar, 0, wx.GROW)
        self.SetSizer(sizer)
        self.Fit()
        print "matplotlib has been changed"
        print "matplotlib panel class with id %s" % self.id
Beispiel #16
0
    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.toolbar = NavigationToolbar2Wx(self.canvas)
        self.toolbar.Realize()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)
        self.Fit()
Beispiel #17
0
    def redraw(self, agg):
        self.canvas.Destroy()
        self.toolbar.Destroy()
        plt = plot.Plot()
        kind = self.frame.plot_type.GetItemLabel(
            self.frame.plot_type.GetSelection())
        errkind = self.frame.err_type.GetItemLabel(
            self.frame.err_type.GetSelection())
        plt.plot(agg, kind=kind, errkind=errkind.lower())  #, within='rows')

        self.canvas = FigureCanvas(self, -1, plt.fig)
        self.toolbar = NavigationToolbar(self.canvas)

        self.sizer.Add(self.toolbar, 0, wx.EXPAND)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.Layout()
Beispiel #18
0
class Plot(wx.Panel):
    'Creates a plotting window'

    def __init__(self, parent, id=-1, dpi=None, **kwargs):
        wx.Panel.__init__(self, parent, id=id, **kwargs)
        self.figure = mpl.figure.Figure(
            dpi=dpi,  #figsize=(5,7)
        )
        self.canvas = Canvas(self, -1, self.figure)
        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)
Beispiel #19
0
class PlotPanel(wx.Panel):
    """
    Panel with embedded matplotlib plots
    """
    def __init__(self,parent):
        wx.Panel.__init__(self,parent,-1)
        self.fig = Figure(figsize=(2,2))
        self.canvas = FigCanvas(self,-1,self.fig)

        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)
    def __init__(self, parent, figure_width=12.0, figure_height=8.5):
        wx.Panel.__init__(self, parent, wx.ID_ANY)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)
        self.ctrl_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.fig = plt.figure(figsize=(figure_width, figure_height),
                              tight_layout=True,
                              frameon=False)
        self.fig.clf()
        self.linestyles = ["-", "--", ":", "-."]
        self.markers = ["^", "v", "+", "d", "o"]
        self.cmap = plt.cm.ScalarMappable(plt.Normalize(0, 1), "rainbow")
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.axlist = []
        self.canvas.mpl_connect('motion_notify_event', self.UpdateCoords)
        self.Bind(EVT_DONE_PLOTTING, self.OnDonePlotting)
        self.plot_toolbar = NavigationToolbar2Wx(self.canvas)
        fw, th = self.plot_toolbar.GetSize().Get()
        self.plot_toolbar.SetSize(wx.Size(fw, th))
        self.plot_toolbar.Realize()
        self.ctrl_sizer.Add(self.plot_toolbar, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.lower_lim_tc = simple_label_tc(self, "lower limit", 0.0, "real")
        self.upper_lim_tc = simple_label_tc(self, "upper limit", 0.0, "real")
        self.axis_choice = wx.Choice(self, wx.ID_ANY)
        self.axis_choice.Append("x")
        self.axis_choice.Append("y1")
        self.axis_choice.Append("y2")
        self.axis_choice.Select(0)
        self.set_lim_button = wx.Button(self, wx.ID_ANY, "Set axis limits")
        self.set_lim_button.Bind(wx.EVT_BUTTON, self.OnSetLim)
        self.auto_lim_button = wx.Button(self, wx.ID_ANY, "Auto limits")
        self.auto_lim_button.Bind(wx.EVT_BUTTON, self.OnAutoLim)
        self.ctrl_sizer.Add(self.lower_lim_tc, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.upper_lim_tc, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.axis_choice, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.set_lim_button, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.auto_lim_button, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.sizer.Add(self.ctrl_sizer, 0, wx.ALL | wx.LEFT, 5)
        self.sizer.Add(self.canvas, 0, wx.ALL | \
                       wx.LEFT, 5)
Beispiel #21
0
    def __init__(self,parent,size=wx.DefaultSize, filename=None, options=None):

        wx.Window.__init__( self, parent, id=-1, style=wx.NO_BORDER)
        self.fig = Figure((21,21),60)
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.toolbar = Toolbar(self.canvas)
        self.choice=PlotChoice(self)
        self.choice.mode="Standard"
        self.toolbar.Realize()
        self.parent=parent
        # On Windows, default frame size behaviour is incorrect
        # you don't need this under Linux
        tw, th = self.toolbar.GetSizeTuple()
        fw, fh = self.canvas.GetSizeTuple()
        self.toolbar.SetSize(wx.Size(fw, th))
        
        # Create a figure manager to manage things
        self.figmgr = FigureManager(self.canvas, 1, self)
        self.Fit()

        self.filename=filename
        if DEBUG :
            DEBUG_MSG("plot :"+filename)
        self.n=0
        self.ni=0
        self.vl=0
        self.vl1=0
        self.sw=0
        self.sw1=0
        self.flag_sum=False
        
        try:          
            [dirname,shortfilename]=os.path.split(filename)
            [basename,extension]=os.path.splitext(shortfilename)

            self.title=basename
            self.filename=dirname+"\\"+basename+".spe"            

            if not options:
                self.options={'units': 'ppm',
                              'titles': 'no',
                              'yoffset': '0.001',
                              'yaxis': 'yes'}
            self.grid=False
        except:
            pass
Beispiel #22
0
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)

        self.subplots = None
        self.rows = None
        self.cols = None
        self.yerr = None
        self.values = None

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)

        plt = plot.Plot()
        self.canvas = FigureCanvas(self, -1, plt.fig)
        self.toolbar = NavigationToolbar(self.canvas)

        self.sizer.Add(self.toolbar, 0, wx.EXPAND)
        self.sizer.Add(self.canvas, 1, wx.GROW)
        self.Fit()
Beispiel #23
0
 def add_toolbar(self):
     self.toolbar = Toolbar(self.canvas)
     self.toolbar.Realize()
     if wx.Platform == '__WXMAC__':
         # Mac platform (OSX 10.3, MacPython) does not seem to cope with
         # having a toolbar in a sizer. This work-around gets the buttons
         # back, but at the expense of having the toolbar at the top
         self.SetToolBar(self.toolbar)
     else:
         # On Windows platform, default window size is incorrect, so set
         # toolbar width to figure width.
         tw, th = self.toolbar.GetSizeTuple()
         fw, fh = self.canvas.GetSizeTuple()
         # By adding toolbar in sizer, we are able to put it at the bottom
         # of the frame - so appearance is closer to GTK version.
         # As noted above, doesn't work for Mac.
         self.toolbar.SetSize(wx.Size(fw, th))
         #self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
         # update the axes menu on the toolbar
         self.toolbar.update()
 def init_ui(self):
     """Creates the user interface"""
     self.init_menu()
     self.SetSize(wx.Size(640, 480))
     self.main_panel = wx.Panel(self)
     self.main_panel_sizer = wx.BoxSizer(wx.VERTICAL)
     self.figure = Figure()
     self.canvas = FigureCanvas(self.main_panel, wx.ID_ANY, self.figure)
     self.main_panel_sizer.Add(self.canvas, 1, sizer_flags, 0)
     self.toolbar = NavigationToolbar2Wx(self.canvas)
     self.toolbar.Realize()
     if wx.Platform == '__WXMAC__':
         self.SetToolBar(self.toolbar)
     else:
         tw, th = self.toolbar.GetSizeTuple()
         fw, fh = self.canvas.GetSizeTuple()
         self.toolbar.SetSize(wx.Size(fw, th))
         self.main_panel_sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND, 0)
     self.toolbar.update()
     self.main_panel.SetSizerAndFit(self.main_panel_sizer)
Beispiel #25
0
 def __init__(self):
     wx.Frame.__init__(self,
                       None,
                       wx.ID_ANY,
                       title='Matplotlib in Wx',
                       size=(600, 400))
     self.figure = Figure(figsize=(6, 4), dpi=100)
     self.axes = self.figure.add_subplot(111)
     x = np.arange(0, 6, .01)
     y = np.sin(x**2) * np.exp(-x)
     self.axes.plot(x, y)
     self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure)
     self.sizer = wx.BoxSizer(wx.VERTICAL)
     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
     self.toolbar = NavigationToolbar2Wx(self.canvas)
     self.toolbar.Realize()
     self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
     self.toolbar.Show()
     self.SetSizer(self.sizer)
     self.Fit()
Beispiel #26
0
    def __init__(self, parent, id=-1, dpi=None, toolbar=True, **kwargs):
        wx.Panel.__init__(self, parent, id=id, **kwargs)
        self.figure = matplotlib.figure.Figure(dpi=dpi,
                                               facecolor=(0.9, 0.9, 0.9, 1))

        self.canvas = Canvas(self, -1, self.figure)
        self.plot_sizer = wx.BoxSizer(wx.VERTICAL)

        if toolbar:
            self.toolbar = Toolbar(self.canvas)
            self.toolbar.Realize()
            self.plot_sizer.Add(self.toolbar, 0,
                                wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        self.plot_sizer.Add(self.canvas, 1, wx.EXPAND)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.plot_sizer, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

        self.setup_events()
Beispiel #27
0
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.label_1 = wx.StaticText(self, -1, "State")
        self.label_2 = wx.StaticText(self, -1, "Frame Nr")
        self.label_3 = wx.StaticText(self, -1, "Node ID")
        self.axes = wx.CheckBox(self, -1, "auto Axes")
        self.axes.SetValue(1)

        self.calibrated = wx.StaticText(self, -1, "not calibrated")
        self.frame_num = wx.StaticText(self, -1, "xxxxxxxx")
        self.node_id = wx.StaticText(self, -1, "xxxxxxxxxxx")

        self.fig = Figure((5, 4), 75)
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
        self.toolbar = NavigationToolbar2Wx(self.canvas)

        self.__set_properties()
        self.__do_layout()
        self.__init_plot()
        self.toolbar.Realize()
        EVT_DATA_EVENT(self, self.display_data)
Beispiel #28
0
    def __init__(self,parent):
        wx.Panel.__init__(self,parent,style = wx.BORDER_SUNKEN)

        self.sliceFigure = Figure(frameon = True,figsize =(2,3))
        self.sliceFigure.set_facecolor('.82')
        self.sliceCanvas = FigureCanvas(self, -1, self.sliceFigure)
        self.sliceCanvas.SetAutoLayout(False)

        self.box = Toolbar(self.sliceCanvas)
        self.box.Hide()
        self.box.zoom()

        self.fm = FigureManagerBase(self.sliceCanvas, 1)
        _pylab_helpers.Gcf.set_active(self.fm)

        self.sliceAxis = self.sliceFigure.add_axes([0.1,0.2,0.8,0.7])

        sliceSizer = wx.BoxSizer(wx.VERTICAL)
        sliceSizer.Add(self.sliceCanvas,1,wx.EXPAND|wx.RIGHT|wx.LEFT,
                                                                    border = 1)
        self.SetSizer(sliceSizer)
        return
Beispiel #29
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)

        self.sliceFigure = Figure(frameon=True, figsize=(2, 3))
        self.sliceFigure.set_facecolor('.82')
        self.sliceCanvas = FigureCanvas(self, -1, self.sliceFigure)
        self.sliceCanvas.SetAutoLayout(False)

        self.box = Toolbar(self.sliceCanvas)
        self.box.Hide()
        self.box.zoom()

        self.fm = FigureManagerBase(self.sliceCanvas, 1)
        _pylab_helpers.Gcf.set_active(self.fm)

        self.sliceAxis = self.sliceFigure.add_axes([0.1, 0.2, 0.8, 0.7])

        sliceSizer = wx.BoxSizer(wx.VERTICAL)
        sliceSizer.Add(self.sliceCanvas,
                       1,
                       wx.EXPAND | wx.RIGHT | wx.LEFT,
                       border=1)
        self.SetSizer(sliceSizer)
        return
Beispiel #30
0
class SitwPanelCanvas(wx.Panel):
    def __init__(self, parent, sitwViewFrame):
        wx.Panel.__init__(self, parent)
        
        self.sitwViewFrame = sitwViewFrame
        
        
        self.Height_Loc = 60
        self.iColWidth = 100
        self.iGraphicHeight = 60 * 24 + self.Height_Loc
        self.iGraphicWidth = self.iColWidth / 2 + 4 * self.iColWidth
        
        
        
        self.figure = Figure()
        #self.figure.patch.set_fc((.9, .9, .9))
        self.figure.patch.set_fc('white')
        self.strTitleTex = self.figure.suptitle('', fontsize = 16, color = 'darkgreen')
        
        self.axes = self.figure.add_subplot(111, axisbg = (.8, .8, .8))
        

        self.axes.set_xlim(0, self.iGraphicWidth)
        self.axes.set_ylim(0, self.iGraphicHeight)
        self.axes.xaxis.set_visible(False)
        #self.axes.yaxis.set_visible(False)

        
        self.majorLocator   = MultipleLocator(60)
        self.majorFormatter = FormatStrFormatter('%d')
        self.minorLocator   = MultipleLocator(15)

        
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.toolbar = NavigationToolbar(self.canvas)
        #self.toolbar.DeleteToolByPos(0) #home
        #self.toolbar.DeleteToolByPos(0) #backward
        #self.toolbar.DeleteToolByPos(0) #forward
        self.toolbar.DeleteToolByPos(7) #subplots
        

        #toolitems = [t for t in NavigationToolbar.toolitems]        
        ##if t[0] in ('Home', 'Pan', 'Zoom', 'Save')]    
        #print 'toolitems', toolitems   
        #print self.toolbar.GetToolsCount(), '###'
        
        
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.sizer.Add(self.toolbar, 0, wx.EXPAND)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        
        self.SetSizer(self.sizer)
        self.Fit()
        
        
        
        
        
        
    def drawGraphLog(self):
        
        strTitle = 'Sitw Usage Log   ' + sitwPara.Default_Year + '-' + sitwPara.Default_Month + '-' + sitwPara.Default_Day 

        self.strTitleTex.set_text(strTitle)
        
        self.axes.clear()
        
        self.axes.set_xlabel('Node') 
        self.axes.set_ylabel('Time')  
        self.axes.xaxis.label.set_color('lightblue')
        self.axes.yaxis.label.set_color('lightblue')
        self.axes.tick_params(axis='x', colors='white')
        self.axes.tick_params(axis='y', colors='white')         
        

        #self.axes.autoscale_view()
        self.axes.grid(True, 'both')
        #self.figure.autofmt_xdate()
        
        self.axes.yaxis.set_major_locator(self.majorLocator)
        self.axes.yaxis.set_major_formatter(self.majorFormatter)
        
        #for the minor ticks, use no labels; default NullFormatter
        self.axes.yaxis.set_minor_locator(self.minorLocator)      
        
        
                        


        '''
        x = []
        y = []
        for item in sitwPara.List_Time_Mark:
            #print item
            #paras = str(item).split('|')
            #print paras            
            
            Xval = 10 
            Ytime = datetime.datetime.fromtimestamp(time.mktime(time.strptime(item, "%Y-%m-%d|%H:%M:%S")))   
                       
            
            x.append(Xval)
            y.append(Ytime)
            
                    
        print x, y
                    
        dates = matplotlib.dates.date2num(y)
        
        print '@', dates, '@'
        '''




        
        for i in range(24):
            self.drawPatch(0, (23 - i) * 60, self.iColWidth / 2, 60, 'lightblue', str(i) + ':00', va = 'top')
        
        idx = 0
        for item in sitwPara.List_Ana_Report:
            strNode = ''
            iActions = 0
            for rec in item:
                paras = str(rec).split('|')
                #print paras, '@@@' 
                sel = self.time2coord(paras[1], paras[2])
                #print sel, '///'
                
                try:
                    colour = sitwPara.Dic_App_Colour[paras[3]]
                except:
                    colour = 'ivory'

                self.drawPatch(self.iColWidth / 2 + idx * self.iColWidth, sel[1] - self.Height_Loc, self.iColWidth, sel[2], colour, paras[3] + ' : ' + paras[4], va = 'center') 
                iActions += int(paras[4]) 
                strNode = paras[0]

            self.drawPatch(self.iColWidth / 2 + idx * self.iColWidth, self.iGraphicHeight - self.Height_Loc, self.iColWidth, self.Height_Loc, 'lightblue', strNode + ' : ' + str(iActions), va = 'center')
            idx += 1
            
            
            
        self.canvas.draw()
        
        
        
        
        
                              
    def time2coord(self, strT1, strT2):
        
        dtTime1 = self.Str2Date(strT1)
        dtTime2 = self.Str2Date(strT2)
        
        iStartPoint = self.iGraphicHeight - (int(dtTime1.hour) * 60 + int(dtTime1.minute))
        iEndPoint = self.iGraphicHeight - (int(dtTime2.hour) * 60 + int(dtTime2.minute))
        iLength = iStartPoint - iEndPoint
        
        return [iStartPoint, iEndPoint, iLength]
        
        
        
    def Str2Date(self, strDateTime):
        ret = datetime.datetime.fromtimestamp(time.mktime(time.strptime(strDateTime,"%Y-%m-%d %H:%M:%S.%f")))
        return ret
        
        
        
        
    def drawPatch(self, x = 0, y = 0, w = 100, h = 15, c = 'lightgrey', t = '', va = 'center'):
        verts = [
            (x, y), # left, bottom
            (x, y + h), # left, top
            (x + w, y + h), # right, top
            (x + w, y), # right, bottom
            (x, y), # ignored
            ]
        
        codes = [Path.MOVETO,
                 Path.LINETO,
                 Path.LINETO,
                 Path.LINETO,
                 Path.CLOSEPOLY,
                 ]
        
        path = Path(verts, codes)
        patch = patches.PathPatch(path, facecolor = c, lw = 1)
        self.axes.add_patch(patch)

        if va == 'top':
            self.axes.text(x + w/2, y + h - 3, t, ha='center', va='top', fontsize=12, color='black').set_clip_on(True)
        elif va == 'center':
            self.axes.text(x + w/2, y + h/2, t, ha='center', va='center', fontsize=12, color='black').set_clip_on(True)
        elif va == 'bottom':
            self.axes.text(x + w/2, y, t, ha='center', va='bottom', fontsize=12, color='black').set_clip_on(True)
Beispiel #31
0
 def __init__(self, plotCanvas):
     NavigationToolbar2Wx.__init__(self, plotCanvas)
     #remove unwanted Buttons
     SUBPLOT_BTN = 6
     self.DeleteToolByPos(SUBPLOT_BTN)
Beispiel #32
0
    def __init__(self,parent,id):
        wx.Panel.__init__(self,parent,id,style=wx.BORDER_SUNKEN)

        self.scale_collection = array([])
        self.real_data = flipud(parent.data.T)
        self.parent = parent

        self.raw_data = flipud(parent.model.T)
        self.scaled_data = copy(self.raw_data)
        self.plot_extent = parent.plot_extent

        lower_lim = amin(self.scaled_data[nonzero(self.scaled_data.real)])

        finite_real = self.real_data[isfinite(self.real_data)]
        finite_real = finite_real[nonzero(finite_real)]

        #Hack
        #self.vmin = amin(log(finite_real.real))
        self.vmax = amax(log(finite_real.real))
        self.vmin = self.vmax - 12
        self.figure = Figure()
        self.axes = self.figure.add_subplot(211)
        self.canvas = FigureCanvas(self, -1, self.figure)

        fm = FigureManagerBase(self.canvas, 0)
        _pylab_helpers.Gcf.set_active(fm)

        # Instantiate the matplotlib navigation toolbar and explicitly show it.
        mpl_toolbar = Toolbar(self.canvas)
        mpl_toolbar.Realize()

        self.myImage = self.showImage(log(abs(self.scaled_data)),self.axes)
        self.modelColor = self.figure.colorbar(self.myImage)

        self.dataaxes = self.figure.add_subplot(212)
        self.datamyImage = self.showImage(log(self.real_data),self.dataaxes)
        self.dataColor = self.figure.colorbar(self.datamyImage)

        self.scale = wx.TextCtrl(self,-1)

        self.updateButton = wx.Button(self,-1,'UPDATE')
        self.resetButton = wx.Button(self,-1,'RESET')
        self.areaScaleButton = wx.Button(self,-1,'AUTO SCALE')


        BotSize = wx.BoxSizer(wx.HORIZONTAL)
        vertSize = wx.BoxSizer(wx.VERTICAL)

        BotSize.Add(self.scale,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.updateButton,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.resetButton,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.areaScaleButton,0,wx.LEFT|wx.RIGHT, border = 5)

        vertSize.Add(self.canvas,-1,wx.EXPAND)
        vertSize.Add(mpl_toolbar,0)
        vertSize.Add(BotSize,0,wx.ALL, border = 10)
        self.SetSizer(vertSize)
        self.Fit()

        self.updateButton.Bind(wx.EVT_BUTTON,self.update)
        self.resetButton.Bind(wx.EVT_BUTTON,self.reset)
        self.areaScaleButton.Bind(wx.EVT_BUTTON,self.autoScale)
 def __init__(self, *args):
     NavigationToolbar2Wx.__init__(self, *args)
     self.play_thread = PlayThread(self, self.canvas)
     self.play_thread.start()
Beispiel #34
0
class PlotFigure(wx.Window):
#============================================================================
    def __init__(self,parent,size=wx.DefaultSize, filename=None, options=None):

        wx.Window.__init__( self, parent, id=-1, style=wx.NO_BORDER)
        self.fig = Figure((21,21),60)
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.toolbar = Toolbar(self.canvas)
        self.choice=PlotChoice(self)
        self.choice.mode="Standard"
        self.toolbar.Realize()
        self.parent=parent
        # On Windows, default frame size behaviour is incorrect
        # you don't need this under Linux
        tw, th = self.toolbar.GetSizeTuple()
        fw, fh = self.canvas.GetSizeTuple()
        self.toolbar.SetSize(wx.Size(fw, th))
        
        # Create a figure manager to manage things
        self.figmgr = FigureManager(self.canvas, 1, self)
        self.Fit()

        self.filename=filename
        if DEBUG :
            DEBUG_MSG("plot :"+filename)
        self.n=0
        self.ni=0
        self.vl=0
        self.vl1=0
        self.sw=0
        self.sw1=0
        self.flag_sum=False
        
        try:          
            [dirname,shortfilename]=os.path.split(filename)
            [basename,extension]=os.path.splitext(shortfilename)

            self.title=basename
            self.filename=dirname+"\\"+basename+".spe"            

            if not options:
                self.options={'units': 'ppm',
                              'titles': 'no',
                              'yoffset': '0.001',
                              'yaxis': 'yes'}
            self.grid=False
        except:
            pass

    def GetToolBar(self):
        # You will need to override GetToolBar if you are using an 
        # unmanaged toolbar in your frame
         
        return self.toolbar
    
    def read_spectra(self):
        #frequency=(i+1)*sw/n-sw/2.
        #ppm=frequency*1.e6/abs(vl)
        DEBUG_MSG("read_spectra : "+self.filename)
        
        try: #Handling filename error (Correction of a bug for NEw in file menu)
            f=open(self.filename,"rb")
        except:
            return False
        
        try: # Handling opening erros
            #first the header
            line=f.readline()    # PULSAR string
            DEBUG_MSG(rtn(line))
            line=f.readline()    # NP string
            DEBUG_MSG(rtn(line))
            items=line.split('=')
            n=int(items[1])     
            line=f.readline()    # SW string
            DEBUG_MSG(rtn(line))
            items=line.split('=')
            sw=float(items[1])
            line=f.readline()    # VL
            DEBUG_MSG(rtn(line))
            items=line.split('=')
            vl=float(items[1])
            line=f.readline()    # NI or LB string?
            DEBUG_MSG(rtn(line))
            items=line.split('=')
            ni=1 #by default
            if string.strip(items[0])=="NI":     
                ni=int(items[1])
                line=f.readline()    #SW1
                DEBUG_MSG(rtn(line))
                items=line.split('=')
                sw1=float(items[1])
                line=f.readline()    #VL1
                DEBUG_MSG(rtn(line))
                items=line.split('=')
                vl1=float(items[1])
                line=f.readline()    #SUM
                DEBUG_MSG(rtn(line))
                items=line.split('=')
                flag_sum=eval(string.upper(items[1]))
                line=f.readline()    # LB string
                DEBUG_MSG(rtn(line))
                items=line.split('=')     
            #now we have to read LB
            self.lb=[]
            self.lb.append(float(items[1]))
            #and GB
            line=f.readline()
            DEBUG_MSG(rtn(line))
            items=line.split('=')
            self.gb=[]
            self.gb.append(float(items[1]))
            #and CONCENTRATION
            line=f.readline() 
            DEBUG_MSG(rtn(line))
            items=line.split('=')
            self.concentration=[]
            self.concentration.append(float(items[1]))
            if ni>1:
                for j in range(ni-1):
                    line=f.readline() #LB
                    DEBUG_MSG(rtn(line))
                    items=line.split('=')
                    self.lb.append(float(items[1]))
                    line=f.readline() #GB
                    DEBUG_MSG(rtn(line))
                    items=line.split('=')
                    self.gb.append(float(items[1]))
                    line=f.readline() #concentration
                    DEBUG_MSG(rtn(line))
                    items=line.split('=')
                    self.concentration.append(float(items[1])) 

            self.ydata = []
            self.spec = []
            
            line=f.readline() # read TYPE
            DEBUG_MSG(rtn(line))

            line=f.readline()  # read YDATA or XDATA
            DEBUG_MSG(rtn(line))

        except: # There was an error
            WRITE_STRING("***ERROR***: Badly formatted header")
            f.close()
            return false

        if string.find(line,"YDATA")>-1: # check if there is a YDATA directive
            try:     
                self.label=string.join(string.split(line)[1:],' ')
                print self.label
                print ni
                for j in range(ni):
                    line=f.readline()
                    if not isinstance(line,str):
                        self.ydata.append(float(line))
                    else:
                        self.ydata.append(line)
            except:
                WRITE_ERROR("bad YDATA labels")
                f.close()
                return false

            line=f.readline()
            DEBUG_MSG(rtn(line)) # read XDATA

        try:
            for j in range(ni):
                DEBUG_MSG("\treading spectrum"+str(j+1))
                xy = []
                DEBUG_MSG("n %13i"%n)
                for i in range(n):
                    line=f.readline()
                    items=line.split(' ')
                    x=float(items[0])
                    y=float(items[1])
                    xy.append(complex(x,y)*self.concentration[j])
                DEBUG_MSG("end reading "+str(j+1))
                self.spec.append(array(xy))

            line=f.readline()       
            DEBUG_MSG(rtn(line))
            if string.find(line,"END")>-1:
                DEBUG_MSG("reading file success!")
        except:
            WRITE_STRING("***ERROR***: problem when reading X,Y data in the *.spe file!")
            f.close()
            return false
            
        self.frequency, self.ppm = [], []
        for i in range(n):
            self.frequency.append((i+1)*sw/n-sw/2.)
            self.ppm.append(((i+1)*sw/n-sw/2.)*1.e6/abs(vl))

        #save some data as class properties
        self.n=n
        self.ni=ni
        self.vl=vl
        self.sw=sw
        if ni > 1:
            self.vl1=vl1
            self.sw1=sw1
            self.flag_sum=flag_sum
            
        #perform the fft and broadening
        addlb(ni, self.spec, self.sw, self.lb, self.gb, self.concentration)

        #sum of the spectra
        if self.flag_sum:
            p=[]
            for i in range (n):
                sum=complex(0.,0.)
                for j in range(ni):
                    sum=sum+self.spec[j][i]
                p.append(sum)      
            self.spec.append(array(p))
            self.ni=ni+1    
        return True
    
    #------------------------------------------------    
    def plot_data(self,mode=None, offset=None):
    #------------------------------------------------
        """ PLOT_SPECTRA:
        Plot one or more 1D spectra on the same figure
        """

        if not mode or mode=='reset':
            try:
                if not self.read_spectra(): return False
            except:
                return False
            
            self.maxi=0
            for j in range(self.ni):
                mxi=max(map(abs,self.spec[j]))
                self.maxi=max(mxi,self.maxi)
                self.offset=0
                
            if self.ni<6:
                mode='standard'
            else:
                mode='popt'

        else:
            mode= string.lower(mode)

##        if mode == 'reset' :
##            try:
##                if not self.read_spectra(): return False
##            except:
##                return False
##                
##            self.maxi=0
##            for j in range(self.ni):
##                mxi=max(map(abs,self.spec[j]))
##                self.maxi=max(mxi,self.maxi)
##            self.offset=0

        mx=self.ni+1
        self.dlg = wx.ProgressDialog("Spectrum plotting",
                       "...wait...",
                       maximum = mx+1,
                       parent=self,
                        # style = wx.PD_CAN_ABORT
                        #| wx.PD_APP_MODAL
                        #| wx.PD_ELAPSED_TIME
                        #| wx.PD_ESTIMATED_TIME
                        #| wx.PD_REMAINING_TIME
                           )

        keepGoing = True
        count = 0
        self.fig.clear()
        self.plotdata = self.fig.add_subplot(111)
        if offset :
            self.offset=offset
        else:
            self.offset=0

        #------------------
        if mode == "popt":

            if self.ni == 1:
                mode=="standard"
            else:
                self.fig.clear()
                self.plotdat=None
                self.plotdata = self.fig.add_subplot(111)
                xticks=[]
                xtickslabel=[]
                spacing=10*(round(log10(self.ni))-1)
                DEBUG_MSG("%5i %5i"%(self.ni, spacing))
                if spacing<2: spacing=2
                for i in range(self.ni):
                    X=[float(self.n-j-1+i*self.n)/self.n for j in range(self.n)]
                    if self.ydata:
                        if i%spacing==0:
                            xticks.append(float(self.n/2+i*self.n)/self.n)
                            if not isinstance(self.ydata[i],str):
                                xtickslabel.append(string.strip(str('%10.3f'%float(self.ydata[i]))))
                            else:
                                xtickslabel.append(string.strip(str('%s'%self.ydata[i])))
                            
                    Y=[k.real for k in self.spec[i]]
                    self.plotdata.plot(X, array(Y))
                    count += 1
                    keepGoing = self.dlg.Update(count)

                self.plotdata.set_xlabel('Index')   
                if self.ydata:
                    self.plotdata.set_xticks(xticks)   
                    self.plotdata.set_xticklabels(xtickslabel)
                    self.plotdata.set_xlabel(self.label)
                    
                self.plotdata.set_ylabel('Intensity (a.u.)\n\n')                   
                self.plotdata.set_title("POPT display, "+self.title)
                self.plotdata.grid(self.grid)
            
        #------------------
        if mode == "popt 2d":
            if self.ni == 1:
                mode=="standard"
            else:                
                self.fig.clear()
                self.plotdata = self.fig.add_subplot(111)

                count += 1
                keepGoing = self.dlg.Update(count)

                X=[]
                Y=[]
                Z=[]
                X=self.ppm
                Y=range(self.ni)
                yticks=[]
                ytickslabel=[]
                spacing=10*(round(log10(self.ni))-1)
                if spacing<2: spacing=2
                maxi=0.
                mini=0.
                for i in range(self.ni):
                    Zt=[k.real for k in self.spec[i]]
                    mxi=max(map(abs,Zt))
                    mni=min(map(abs,Zt))
                    maxi=max(maxi,mxi)
                    mini=min(mini,mni)
                    Z.append(array(Zt))
                    if self.ydata:
                        if i%spacing==0:
                            yticks.append(i)
                            ytickslabel.append(string.strip(str('%10.3f'%self.ydata[i])))
                amp=(maxi-mini)
                levels=arange(mini-amp*.05,maxi+amp*.05,amp/self.ni)
                print mini,maxi
                cmap=pylab.cm.get_cmap('jet', len(levels)-1)
                
                cset = self.plotdata.contourf(X, Y, Z, levels, cmap=cmap,)

                #cset2 = self.plotdata.contour(X, Y, Z, cset.levels,
                #        colors = 'k',
                #        hold='on')
                self.plotdata.set_xlim(self.ppm[len(self.ppm)-1],self.ppm[0])
                self.plotdata.set_xlabel('Chemical shift (ppm)')
                self.plotdata.set_ylabel('Index\n')
                if self.ydata:
                    self.plotdata.set_yticks(yticks)   
                    self.plotdata.set_yticklabels(ytickslabel)
                    self.plotdata.set_ylabel(self.label+'\n')

                self.plotdata.set_title("POPT 2D display, "+self.title)
    ##                clabels=[mini,0.,maxi]
    ##                self.fig.colorbar(cset,clabels=clabels)
    ##                #self.plotdata.grid(self.grid)


        if mode == 'reset' or mode=="standard" :
            #print string.lower(self.options['units'])
            if string.lower(self.options['units'])=="hz":
                for i in range(self.ni):
                    spec=[]
                    shift=(i+1)*self.offset*self.maxi           
                    spec=[shift + x.real for x in self.spec[i]]
                    self.plotdata.plot(self.frequency, array(spec))
                    count += 1
                    keepGoing = self.dlg.Update(count)
                self.plotdata.set_xlim(self.frequency[len(self.frequency)-1],self.frequency[0])
                self.plotdata.set_xlabel('Frequency (Hz)')
            else:
                for i in range(self.ni):
                    shift=(i+1)*self.offset*self.maxi           
                    spec=[shift + x.real for x in self.spec[i]]
                    self.plotdata.plot(self.ppm, array(spec))
                    count += 1
                    keepGoing = self.dlg.Update(count)
                self.plotdata.set_xlim(self.ppm[len(self.ppm)-1],self.ppm[0])
                self.plotdata.set_xlabel('Chemical shift (ppm)')
            if string.lower(self.options['yaxis'])!="no": 
                self.plotdata.set_ylabel('Intensity (a.u.)\n')
            else:    
                self.plotdata.set_yticks([])   
                self.plotdata.set_yticklabels([])         
            self.plotdata.set_title(self.title)
            self.plotdata.grid(self.grid)

       #update everything and exit
        self.canvas.draw()
        self.toolbar.update()

        self.dlg.Destroy()
        return True
Beispiel #35
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour('#DCE5EE')

        pub().subscribe(self.update_language, T.LANGUAGE_CHANGED)

        self.control_panel = None
        self.dframes = []
        self.order_names = []
        self.key_figure = 1
        self.mode_run = False

        self.current_dataframes = None
        self.current_datacolors = None

        self.run_explorer = False

        self.figure_config_dialog_ref = None

        # ---- inicialización de figura
        self.fig = Figure()
        self.canvas = FigureCanvas(self, -1, self.fig)

        # ---- configuración de figura
        self.fig_config = FigureConfig()
        self.set_figure_config()

        # ---- configuración de axe
        self.ax_conf = AxesConfig()

        # ---- radar chard config
        self.radar_chard_con = RadarChadConfig()

        # ---- toolbar
        self.sizer_tool = wx.BoxSizer(wx.HORIZONTAL)
        _bitmap = play_fig.GetBitmap()
        self.b_play = wx.BitmapButton(self, -1, _bitmap, style=wx.NO_BORDER)
        self.sizer_tool.Add(self.b_play, flag=wx.ALIGN_CENTER_VERTICAL)
        self.b_play.Bind(wx.EVT_BUTTON, self.on_play)
        self.b_play.SetToolTipString(L('VISUALIZE_DATE_CLUSTER'))
        _bitmap = settings_fig.GetBitmap()
        self.b_setting = wx.BitmapButton(self, -1, _bitmap, style=wx.NO_BORDER)
        self.sizer_tool.Add(self.b_setting, flag=wx.ALIGN_CENTER_VERTICAL)
        self.b_setting.Bind(wx.EVT_BUTTON, self.on_config)
        self.b_setting.SetToolTipString(L('FIGURE_CONF'))

        _bitmap = sort_and_filter.GetBitmap()
        self.b_sorted = wx.BitmapButton(self, -1, _bitmap, style=wx.NO_BORDER)
        self.b_sorted.Bind(wx.EVT_BUTTON, self.on_sort_and_filter)
        self.b_sorted.SetToolTipString(L('BUTTON_ORDER_AND_FILTER'))
        self.b_sorted.Disable()
        self.sizer_tool.Add(self.b_sorted, 0, wx.ALIGN_CENTER_VERTICAL)

        _bp = line_highligh.GetBitmap()
        self.b_highligh = wx.BitmapButton(self, -1, _bp, style=wx.NO_BORDER)
        self.b_highligh.Bind(wx.EVT_BUTTON, self.on_highligh)
        self.b_highligh.SetToolTipString(L('BUTTON_HIGHLIGHT'))
        self.b_highligh.Disable()
        self.sizer_tool.Add(self.b_highligh, 0, wx.ALIGN_CENTER_VERTICAL)

        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()
        self.toolbar.SetBackgroundColour('#DCE5EE')

        self.sizer_tool.Add(self.toolbar, 0, wx.ALIGN_CENTER_VERTICAL)

        choice_grafic = self.get_choice_grafic()
        self.sizer_tool.Add(choice_grafic, wx.ALIGN_LEFT)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.sizer_tool, 0, wx.EXPAND)
        self.sizer.Add(self.canvas, 1, wx.EXPAND)

        self.SetSizer(self.sizer)
        self.Fit()
        self._welcome()
Beispiel #36
0
class FigurePanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour('#DCE5EE')

        pub().subscribe(self.update_language, T.LANGUAGE_CHANGED)

        self.control_panel = None
        self.dframes = []
        self.order_names = []
        self.key_figure = 1
        self.mode_run = False

        self.current_dataframes = None
        self.current_datacolors = None

        self.run_explorer = False

        self.figure_config_dialog_ref = None

        # ---- inicialización de figura
        self.fig = Figure()
        self.canvas = FigureCanvas(self, -1, self.fig)

        # ---- configuración de figura
        self.fig_config = FigureConfig()
        self.set_figure_config()

        # ---- configuración de axe
        self.ax_conf = AxesConfig()

        # ---- radar chard config
        self.radar_chard_con = RadarChadConfig()

        # ---- toolbar
        self.sizer_tool = wx.BoxSizer(wx.HORIZONTAL)
        _bitmap = play_fig.GetBitmap()
        self.b_play = wx.BitmapButton(self, -1, _bitmap, style=wx.NO_BORDER)
        self.sizer_tool.Add(self.b_play, flag=wx.ALIGN_CENTER_VERTICAL)
        self.b_play.Bind(wx.EVT_BUTTON, self.on_play)
        self.b_play.SetToolTipString(L('VISUALIZE_DATE_CLUSTER'))
        _bitmap = settings_fig.GetBitmap()
        self.b_setting = wx.BitmapButton(self, -1, _bitmap, style=wx.NO_BORDER)
        self.sizer_tool.Add(self.b_setting, flag=wx.ALIGN_CENTER_VERTICAL)
        self.b_setting.Bind(wx.EVT_BUTTON, self.on_config)
        self.b_setting.SetToolTipString(L('FIGURE_CONF'))

        _bitmap = sort_and_filter.GetBitmap()
        self.b_sorted = wx.BitmapButton(self, -1, _bitmap, style=wx.NO_BORDER)
        self.b_sorted.Bind(wx.EVT_BUTTON, self.on_sort_and_filter)
        self.b_sorted.SetToolTipString(L('BUTTON_ORDER_AND_FILTER'))
        self.b_sorted.Disable()
        self.sizer_tool.Add(self.b_sorted, 0, wx.ALIGN_CENTER_VERTICAL)

        _bp = line_highligh.GetBitmap()
        self.b_highligh = wx.BitmapButton(self, -1, _bp, style=wx.NO_BORDER)
        self.b_highligh.Bind(wx.EVT_BUTTON, self.on_highligh)
        self.b_highligh.SetToolTipString(L('BUTTON_HIGHLIGHT'))
        self.b_highligh.Disable()
        self.sizer_tool.Add(self.b_highligh, 0, wx.ALIGN_CENTER_VERTICAL)

        self.toolbar = Toolbar(self.canvas)
        self.toolbar.Realize()
        self.toolbar.SetBackgroundColour('#DCE5EE')

        self.sizer_tool.Add(self.toolbar, 0, wx.ALIGN_CENTER_VERTICAL)

        choice_grafic = self.get_choice_grafic()
        self.sizer_tool.Add(choice_grafic, wx.ALIGN_LEFT)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.sizer_tool, 0, wx.EXPAND)
        self.sizer.Add(self.canvas, 1, wx.EXPAND)

        self.SetSizer(self.sizer)
        self.Fit()
        self._welcome()

    def _welcome(self):
        Axes3D(self.fig)

    def set_figure_config(self):

        self.fig.set_figwidth(self.fig_config.width)
        self.fig.set_figheight(self.fig_config.height)
        self.fig.set_facecolor(self.fig_config.facecolor)

        left = self.fig_config.subplot_left
        bottom = self.fig_config.subplot_bottom
        right = self.fig_config.subplot_right
        top = self.fig_config.subplot_top
        wspace = self.fig_config.subplot_wspace
        hspace = self.fig_config.subplot_hspace
        self.fig.subplots_adjust(left, bottom, right, top, wspace, hspace)

        self.fig.suptitle('Tava Tool',
                          fontsize=14,
                          fontweight='light',
                          style='italic',
                          family='serif',
                          color='c',
                          horizontalalignment='center',
                          verticalalignment='center')

    def draw_graphic(self, dframes, colors):
        key_figure = self.g_figure()
        if key_figure == K_PARALLEL_COORDENATE:
            return kparallelcoordinates(dframes, 'Name', self.fig,
                                        self.ax_conf, self.fig_config, colors)

        elif key_figure == K_RADAR_CHART_POLYGON:
            return radarchart(dframes, 'Name', self.fig, self.ax_conf,
                              self.radar_chard_con, colors)
        elif key_figure == K_RADVIZ:
            return kradviz(dframes, 'Name', self.fig, self.ax_conf, colors)

    def kdraw(self, dframes, colors, ldic):

        self.current_dataframes = dframes
        self.current_datacolors = colors
        self.ldic = ldic
        self._kdraw(dframes, colors)

    def pre_kdraw_order(self, names_ordered):
        names_ordered.append('Name')
        _dframes = []
        for df in self.current_dataframes:
            _dframes.append(df[names_ordered])

        self._kdraw(_dframes, self.current_datacolors)

    def _kdraw(self, dframes, colors):
        self.fig.clear()
        self.start_busy()
        task = DrawThread(self, dframes, colors)
        task.start()

    def on_play(self, event):
        self.mode_run = True
        self.run_explorer = True
        self.new_order = []
        # ---- dibujar clusters/datos seleccionados
        self.control_panel.run_fig()

    def on_sort_and_filter(self, event):

        self.run_explorer = True
        cdf = self.current_dataframes
        if cdf is None or cdf == []:
            return

        self.old_order = cdf[0].columns.tolist()[:-1]
        ItemsPickerFilterDialog(self, self.old_order)

    def on_highligh(self, event):
        _label_aux = ''
        if self.run_explorer:
            for axe in self.fig.get_axes():
                lines = []
                for line in axe.get_children():
                    if isinstance(line, Line2D):
                        if self.ldic.get(line.get_color()) is not None:
                            _label_aux = self.ldic.get(line.get_color())
                            line.set_label('shape = ' +
                                           self.ldic.get(line.get_color()))
                            lines.append(line)
                        else:
                            line.set_label('')
                h = resaltar(lines,
                             highlight_color=self.ax_conf.highlight_color,
                             formatter='{label}'.format)
                if lines != []:
                    h.show_highlight(lines[0])
            self.run_explorer = False
            self.canvas_draw()

    def on_config(self, event):
        if self.figure_config_dialog_ref is None:
            self.figure_config_dialog_ref = FigureConfigDialog(self)
        else:
            self.figure_config_dialog_ref.nb.SetSelection(0)
            self.figure_config_dialog_ref.ShowModal()

    def g_figure(self):
        return self.ch_graph.GetSelection()

    def get_choice_grafic(self):
        grid = wx.FlexGridSizer(cols=2)
        sampleList = self.get_item_list()

        self.ch_graph = wx.Choice(self, -1, choices=sampleList)
        self.ch_graph.SetSelection(0)
        self.ch_graph.Bind(wx.EVT_CHOICE, self.on_graphic)
        self.ch_graph.SetToolTipString(L('SELECT_A_GRAPHIC'))

        grid.Add(self.ch_graph, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        return grid

    def get_item_list(self):
        return [L('PARALLEL_COORDINATES'), 'Radar Chart']

    def on_graphic(self, event):

        if event.GetString() != L('PARALLEL_COORDINATES') or not self.mode_run:
            self.b_highligh.Disable()
            return
        self.b_highligh.Enable()

    def update_language(self, msg):
        s = self.ch_graph.GetSelection()
        self.ch_graph.SetItems(self.get_item_list())
        self.ch_graph.SetSelection(s)
        self.ch_graph.SetToolTipString(L('SELECT_A_GRAPHIC'))
        self.b_setting.SetToolTipString(L('FIGURE_CONF'))
        self.b_play.SetToolTipString(L('VISUALIZE_DATE_CLUSTER'))

    def start_busy(self):
        pub().sendMessage(T.START_BUSY)
        self.b_play.Disable()
        self.toolbar.Disable()
        self.b_setting.Disable()
        self.ch_graph.Disable()
        self.b_highligh.Disable()
        self.b_sorted.Disable()

    def stop_busy(self):
        pub().sendMessage(T.STOP_BUSY)
        self.b_play.Enable()
        self.toolbar.Enable()
        self.b_setting.Enable()
        self.ch_graph.Enable()
        self.b_highligh.Enable()
        self.b_sorted.Enable()

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

    def set_fig(self, fig):
        self.fig = fig