Changeset 6356


Ignore:
Timestamp:
Feb 17, 2009, 4:03:35 PM (16 years ago)
Author:
rwilson
Message:

Added controls for graph title and legend. Moved to v 0.2.

Location:
misc/tools/plotcsv
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • misc/tools/plotcsv/installer/plotcsv.nsi

    r6348 r6356  
    11!define PRODUCT_NAME "plotcsv"
    2 !define PRODUCT_VERSION "0.1"
     2!define PRODUCT_VERSION "0.2"
    33!define ICON_FILE "plotcsv.ico"
    44
  • misc/tools/plotcsv/plotcsv.py

    r6352 r6356  
    1313import time
    1414import getopt
    15 import pylab
    1615try:
    1716    import cpickle
    1817except:
    1918    import pickle
     19
     20try:
     21    import pylab
     22except ImportError:
     23    import tkinter_error
     24    msg = ('Sorry, you have to install matplotlib.\n'
     25           'Get it from either:\n'
     26           r'   N:\georisk\downloads\matplotlib, or' '\n'
     27           '   [http://matplotlib.sourceforge.net/].\n\n'
     28           'You will also need to have numpy installed:\n'
     29           r'   N:\georisk\downloads\numpy')
     30    tkinter_error.tkinter_error(msg)
     31    print msg
     32    sys.exit(1)
    2033
    2134try:
     
    4053# program name and version
    4154APP_NAME = 'plotcsv'
    42 APP_VERSION = '0.1'
     55APP_VERSION = '0.2'
    4356
    4457# name of the configuration filename
     
    5972BOX_CSV_HEIGHT = 265
    6073BOX_PLOT_WIDTH = 400
    61 BOX_PLOT_HEIGHT = 90
     74BOX_PLOT_HEIGHT = 140
    6275
    6376TXT_CSVFILE_WIDTH = 390
     
    7083
    7184FORM_WIDTH = BOX_WIDTH + 15
    72 FORM_HEIGHT = 405
     85FORM_HEIGHT = 455
    7386
    7487START_YOFFSET = 7
     
    291304# @param x_hdr The X axis label string.
    292305# @param y_hdr The Y axis label string.
    293 def plot_files(filenames, x_hdr, y_hdr):
     306def plot_files(filenames, x_hdr, y_hdr, title='', legend=False):
    294307    pylab.rc('axes', linewidth=2)
    295308    pylab.xlabel(x_hdr.title())
     
    301314        pylab.plot(x_data, y_data)
    302315
    303     (min_y, max_y) = pylab.ylim()
    304     range_y = max_y - min_y
    305     add_y = float(range_y) / 5
    306     pylab.ylim((min_y, max_y+add_y))
    307     pylab.legend(filenames, 'upper left')
     316    if title:
     317        pylab.title(title)
     318    if legend:
     319        (min_y, max_y) = pylab.ylim()
     320        range_y = max_y - min_y
     321        add_y = float(range_y) / 5
     322        pylab.ylim((min_y, max_y+add_y))
     323        pylab.legend(filenames, 'upper left')
    308324
    309325    pylab.show()
     
    369385        self.cbYColHdr = wx.Choice(p, -1, pos=(x+65, Y_OFFSET), size=(80, -1))
    370386        self.YColHdr = []
    371 
     387        Y_OFFSET += GEN_DELTAY*2
     388
     389        self.chkLegend = wx.CheckBox(p, -1, " Show graph legend",
     390                                     pos=(COLLAB_X_OFFSET, Y_OFFSET))
     391       
     392        Y_OFFSET += GEN_DELTAY
     393        wx.StaticText(p, -1, 'Title',
     394                      pos=(18, Y_OFFSET+LAB_CTRL_OFFSET+2), style=wx.ALIGN_LEFT)
     395        self.txtTitle = wx.TextCtrl(p, -1, "", size=(350, -1),
     396                                    pos=(COLLAB_X_OFFSET+20,
     397                                         Y_OFFSET+LAB_CTRL_OFFSET),
     398                                    style=wx.ALIGN_LEFT)
     399       
    372400        Y_OFFSET += BUTTON_HEIGHT + MARGIN
    373401        x = FORM_WIDTH/2 - BUTTON_WIDTH/2
     
    438466        self.cfg['YColHdrSelection'] = self.cbYColHdr.GetSelection()
    439467        self.cfg['file_dir'] = self.file_dir
     468        self.cfg['GraphTitle'] = self.txtTitle.GetValue()
     469        self.cfg['GraphLegend'] = self.chkLegend.GetValue()
    440470
    441471        self.cfg.save()
     
    473503        if self.YColHdrSelection >= 0:
    474504            self.cbYColHdr.SetSelection(self.YColHdrSelection)
     505        title = self.cfg['GraphTitle']
     506        if title is None:
     507            title = ''
     508        self.txtTitle.SetValue(title)
     509        if self.cfg['GraphLegend']:
     510            self.chkLegend.SetValue(True)
    475511
    476512    def getHeaders(self, filename):
     
    556592
    557593        if selected_x and selected_y:
    558             plot_files(self.CSVFiles, selected_x, selected_y)
     594            plot_files(self.CSVFiles, selected_x, selected_y,
     595                       title=self.txtTitle.GetValue(),
     596                       legend=self.chkLegend.GetValue())
    559597           
    560598    def error(self, msg):
Note: See TracChangeset for help on using the changeset viewer.