Ignore:
Timestamp:
Feb 18, 2009, 8:50:16 AM (16 years ago)
Author:
rwilson
Message:

Added short filenames in legend option.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/tools/plotcsv/plotcsv.py

    r6356 r6358  
    8383
    8484FORM_WIDTH = BOX_WIDTH + 15
    85 FORM_HEIGHT = 455
     85FORM_HEIGHT = 450
    8686
    8787START_YOFFSET = 7
     
    304304# @param x_hdr The X axis label string.
    305305# @param y_hdr The Y axis label string.
    306 def plot_files(filenames, x_hdr, y_hdr, title='', legend=False):
     306# @param title The string used to title the graph.
     307# @param legend True if a legend is to be displayed.
     308# @param legend_path True if legend is to contain full file paths.
     309def plot_files(filenames, x_hdr, y_hdr, title='', legend=False,
     310               legend_path=False):
    307311    pylab.rc('axes', linewidth=2)
    308312    pylab.xlabel(x_hdr.title())
     
    321325        add_y = float(range_y) / 5
    322326        pylab.ylim((min_y, max_y+add_y))
    323         pylab.legend(filenames, 'upper left')
     327        legend_names = filenames
     328        if not legend_path:
     329            legend_names = [os.path.basename(x) for x in filenames]
     330        pylab.legend(legend_names, 'upper right')
     331#        pylab.legend(legend_names, 'upper left')
    324332
    325333    pylab.show()
     
    388396
    389397        self.chkLegend = wx.CheckBox(p, -1, " Show graph legend",
    390                                      pos=(COLLAB_X_OFFSET, Y_OFFSET))
    391        
    392         Y_OFFSET += GEN_DELTAY
     398                                     pos=(COLLAB_X_OFFSET+20, Y_OFFSET))       
     399        self.chkLegendPath = wx.CheckBox(p, -1, " Full file path in legend",
     400                                         pos=(COLLAB_X_OFFSET+180, Y_OFFSET))       
     401        Y_OFFSET += GEN_DELTAY + 3
     402       
    393403        wx.StaticText(p, -1, 'Title',
    394404                      pos=(18, Y_OFFSET+LAB_CTRL_OFFSET+2), style=wx.ALIGN_LEFT)
     
    407417        self.Bind(wx.EVT_BUTTON, self.DelCSVFile, self.btnDelCSVFile)
    408418        self.Bind(wx.EVT_BUTTON, self.PlotFiles, self.btnPlot)
     419        self.Bind(wx.EVT_CHECKBOX, self.ChangeLegend, self.chkLegend)
    409420       
    410421        self.Bind(wx.EVT_CLOSE, self.doStateSave)
     
    457468            self.updateHdrChoices()
    458469
     470    def ChangeLegend(self, event):
     471        if self.chkLegend.GetValue():
     472            self.chkLegendPath.Enable()
     473        else:
     474            self.chkLegendPath.Disable()
     475
    459476    def doStateSave(self, event):
    460477        """Save state from 'self' variables & controls."""
     
    468485        self.cfg['GraphTitle'] = self.txtTitle.GetValue()
    469486        self.cfg['GraphLegend'] = self.chkLegend.GetValue()
     487        self.cfg['LegendPath'] = self.chkLegendPath.GetValue()
    470488
    471489        self.cfg.save()
     
    509527        if self.cfg['GraphLegend']:
    510528            self.chkLegend.SetValue(True)
    511 
     529        if self.cfg['LegendPath']:
     530            self.chkLegendPath.SetValue(True)
     531        self.ChangeLegend(None)
     532       
    512533    def getHeaders(self, filename):
    513534        '''Get header list from a file'''
     
    594615            plot_files(self.CSVFiles, selected_x, selected_y,
    595616                       title=self.txtTitle.GetValue(),
    596                        legend=self.chkLegend.GetValue())
     617                       legend=self.chkLegend.GetValue(),
     618                       legend_path=self.chkLegendPath.GetValue())
    597619           
    598620    def error(self, msg):
Note: See TracChangeset for help on using the changeset viewer.