class MyTest(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.mySprSht = SpreadSheet() def tearDown(self): unittest.TestCase.tearDown(self) del (self.mySprSht) def test_should_always_pass_cleanly(self): """Should always pass cleanly.""" pass def test_myclass_existence(self): """Check that myclass exists""" result = self.mySprSht # See if the self.mySprSht object exists self.assertTrue(result) def test_save(self): """Check that save operates cleanly""" list_of_rows = ALT_DATA self.mySprSht.add_sheet('Alt_Data', list_of_rows) self.mySprSht.add_scatter( 'Alt_Plot', 'Alt_Data', title='Unittest Title', xlabel='Unittest X Axis', ylabel='Unittest Y Axis', y2label='Unittest Y2 Axis', xcol=1, ycolL=[2, 3, 4], ycol2L=None, showMarkerL=[1, 1, 1], showMarker2L=None, lineThkL=["0.1in", "0.01in"], lineStyleL=[1, 2, 3], colorL=None, #['cyan','GRaY','#69a'], #['#666666'], labelL=None, label2L=None) self.mySprSht.setXrange(-10000, 70000, plot_sheetname=None) self.mySprSht.setYrange(-100, 700) #self.mySprSht.add_scatter( 'Alt_Plot2', 'Alt_Data') #self.mySprSht.add_scatter( 'Alt_Plot3', 'Alt_Data') self.mySprSht.save(filename=os.path.join(here, 'alt')) def test_save_secondary_y(self): """Check that save operates for a second y axis""" list_of_rows = ALT_DATA_WIDE self.mySprSht.add_sheet('Alt_Data', list_of_rows) self.mySprSht.add_scatter( 'Alt_Plot', 'Alt_Data', title='Unittest Title', xlabel='Unittest X Axis', ylabel='Unittest Y Axis', y2label='Unittest Y2 Axis', xcol=1, ycolL=[2, 5, 6], ycol2L=[3, 4], lineThkL=[1, 2, 3], lineThk2L=[3.5, 1.5], lineStyle2L=[4, 5], showMarkerL=[1, 1, 1], showMarker2L=None, showLineL=[0, 1, 0], showLine2L=[1, 1], #colorL=['r','g','b'], excel_colors=False, color2L=['c','dc'], labelL=None, label2L=None) self.mySprSht.setY2range(50, 550) self.mySprSht.save(filename=os.path.join(here, 'alt_y2')) def test_logx_save(self): """Check that save operates cleanly""" list_of_rows = ALT_DATA self.mySprSht.add_sheet('Alt_Data', list_of_rows) self.mySprSht.add_scatter('Alt_Plot', 'Alt_Data', title='Unittest Title', xlabel='Unittest X Axis', ylabel='Unittest Y Axis', y2label='Unittest Y2 Axis', xcol=1, logx=True, ycolL=[3, 4], ycol2L=None, showMarkerL=[1, 1, 1], showMarker2L=None, colorL=None, labelL=None, label2L=None) self.mySprSht.save(filename=os.path.join(here, 'alt_logx')) def test_logy_save(self): """Check that save operates cleanly""" list_of_rows = ALT_DATA self.mySprSht.add_sheet('Alt_Data', list_of_rows) self.mySprSht.add_scatter('Alt_Plot', 'Alt_Data', title='Unittest Title', xlabel='Unittest X Axis', ylabel='Unittest Y Axis', y2label='Unittest Y2 Axis', xcol=1, logy=True, ycolL=[3, 4], ycol2L=None, showMarkerL=[1, 1, 1], showMarker2L=None, colorL=None, labelL=None, label2L=None) self.mySprSht.save(filename=os.path.join(here, 'alt_logy')) def test_log2y_save(self): """Check that save operates for a second y axis""" list_of_rows = ALT_DATA_WIDE self.mySprSht.add_sheet('Alt_Data', list_of_rows) self.mySprSht.add_scatter('Alt_Plot', 'Alt_Data', title='Unittest Title', xlabel='Unittest X Axis', ylabel='Unittest Y Axis', y2label='Unittest Y2 Axis', xcol=1, log2y=True, ycolL=[2, 5, 6], ycol2L=[3, 4], showMarkerL=[1, 1, 1], showMarker2L=None, colorL=None, labelL=None, label2L=None) self.mySprSht.save(filename=os.path.join(here, 'alt_log2y')) def test_all_log_save(self): """Check that save operates for a second y axis""" list_of_rows = ALT_DATA_WIDE self.mySprSht.add_sheet('Alt_Data', list_of_rows) self.mySprSht.add_scatter('Alt_Plot', 'Alt_Data', title='Unittest Title', xlabel='Unittest X Axis', ylabel='Unittest Y Axis', y2label='Unittest Y2 Axis', xcol=1, log2y=True, logx=True, logy=True, ycolL=[2, 5, 6], ycol2L=[3, 4], showMarkerL=[1, 1, 1], showMarker2L=None, colorL=None, labelL=None, label2L=None) self.mySprSht.save(filename=os.path.join(here, 'alt_all_log'))
""" This example demonstrates large data sets """ from math import * from odscharts.spreadsheet import SpreadSheet mySprSht = SpreadSheet() list_of_rows = [['Angle', 'Sine', 'Cosine'], ['deg', '', '']] for iang in range(3601): ang_deg = float(iang) / 10.0 ang = radians(ang_deg) list_of_rows.append([ang_deg, sin(ang), cos(ang)]) mySprSht.add_sheet('Trig_Data', list_of_rows) mySprSht.add_scatter('Trig_Plot', 'Trig_Data', title='Trig Functions', xlabel='Angle', ylabel='Trig Function', xcol=1, ycolL=[2, 3], showMarkerL=[1, 0]) mySprSht.save(filename='trig_plot', launch=True)
ylabel='Percent of Aussie Population', y2label='Percent of USA Population', xcol=1, ycolL=[2, 3, 4], showMarkerL=[ 0, ], lineStyleL=[ 1, ], lineThkL=[ 2, ], colorL=['r', 'g', 'b']) mySprSht.add_curve('Combo2_Plot', 'USA_Data', xcol=1, ycol2L=[2, 3, 4], showMarker2L=[ 0, ], lineThk2L=[ 2, ], color2L=['r', 'g', 'b']) mySprSht.setYrange(ymin=0, ymax=80, plot_sheetname=None) mySprSht.setY2range(ymin=0, ymax=80, plot_sheetname=None) mySprSht.save(filename='bmi_index.ods', launch=True)
mySprSht = SpreadSheet() rev_orderL = list(range(10, -1, -1)) toprow = ['Line Style Index'] unitsrow = [''] toprow.extend(['%i) %s' % (i, sL[i]) for i in rev_orderL]) unitsrow.extend(['' for i in rev_orderL]) xbegrow = [0] xbegrow.extend([i for i in rev_orderL]) xendrow = [1] xendrow.extend([i for i in rev_orderL]) list_of_rows = [toprow, unitsrow, xbegrow, xendrow] mySprSht.add_sheet('Line_Style_Data', list_of_rows) mySprSht.add_scatter('Line_Style', 'Line_Style_Data', title='Line Styles', xlabel='', ylabel='Index of Line Style', xcol=1, ycolL=[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], lineStyleL=[i for i in rev_orderL], lineThkL=[1.5], showMarkerL=[0]) mySprSht.setYrange(ymin=-1, ymax=None, plot_sheetname=None) mySprSht.save(filename='line_style_plot', launch=True)
mySprSht = SpreadSheet() rev_orderL = list( range(10,-1,-1) ) toprow = ['Line Style Index'] unitsrow = [''] toprow.extend( ['%i) %s'%(i,sL[i]) for i in rev_orderL] ) unitsrow.extend( ['' for i in rev_orderL] ) xbegrow = [0] xbegrow.extend( [i for i in rev_orderL] ) xendrow = [1] xendrow.extend( [i for i in rev_orderL] ) list_of_rows = [toprow, unitsrow, xbegrow, xendrow] mySprSht.add_sheet('Line_Style_Data', list_of_rows) mySprSht.add_scatter( 'Line_Style', 'Line_Style_Data', title='Line Styles', xlabel='', ylabel='Index of Line Style', xcol=1, ycolL=[2,3,4,5,6,7,8,9,10,11,12], lineStyleL=[i for i in rev_orderL], lineThkL = [1.5], showMarkerL=[0]) mySprSht.setYrange( ymin=-1, ymax=None, plot_sheetname=None) mySprSht.save( filename='line_style_plot', launch=True)
dataL = [] for bm, mr in zip(body_mass, metabolic_rate): dataL.append([bm, mr]) dataL.sort() # create a list of curve fit data for row in dataL: bm, mr = row row.append(0.022110831039 * bm**0.745374452331) list_of_rows = [['Body Mass', 'Rate Data', 'Fitted Rate'], ['g', 'mLO2/hr', 'mLO2/hr']] list_of_rows.extend(dataL) mySprSht = SpreadSheet() mySprSht.add_sheet('MassRate_Data', list_of_rows) mySprSht.add_scatter('MassRate_Plot', 'MassRate_Data', title='Metabolic Rate vs Body Mass', xlabel='Body Mass', ylabel='Metabolic Rate', xcol=1, logx=1, logy=1, showLineL=[0, 1], showMarkerL=[1, 0], ycolL=[2, 3]) mySprSht.setXrange(xmin=1000) mySprSht.save(filename='mass_vs_rate', launch=True)
""" This example demonstrates a simple chart """ from odscharts.spreadsheet import SpreadSheet mySprSht = SpreadSheet() list_of_rows = [ ["Altitude", "Pressure"], ["feet", "psia"], [0, 14.7], [5000, 12.23], [10000, 10.11], [30000, 4.36], [60000, 1.04], ] mySprSht.add_sheet("Alt_Data", list_of_rows) mySprSht.add_scatter( "Alt_P_Plot", "Alt_Data", title="Pressure vs Altitude", xlabel="Altitude", ylabel="Pressure", xcol=1, ycolL=[2] ) mySprSht.save(filename="alt_vs_press") mySprSht.launch_application()
148.949, 11.966, 46.414, 123.287, 106.663, 20.619, 180.150, 200.830, 224.779, 148.940, 112.430, 286.847, 46.347, 142.863, 106.670, 119.660, 104.150, 33.165, 4.900, 4.865] dataL = [] for bm, mr in zip(body_mass, metabolic_rate): dataL.append( [bm,mr] ) dataL.sort() # create a list of curve fit data for row in dataL: bm, mr = row row.append( 0.022110831039*bm**0.745374452331 ) list_of_rows = [['Body Mass','Rate Data','Fitted Rate'], ['g','mLO2/hr','mLO2/hr']] list_of_rows.extend( dataL ) mySprSht = SpreadSheet() mySprSht.add_sheet('MassRate_Data', list_of_rows) mySprSht.add_scatter( 'MassRate_Plot', 'MassRate_Data', title='Metabolic Rate vs Body Mass', xlabel='Body Mass', ylabel='Metabolic Rate', xcol=1, logx=1, logy=1, showLineL=[0,1], showMarkerL=[1,0], ycolL=[2,3]) mySprSht.setXrange(xmin=1000) mySprSht.save( filename='mass_vs_rate', launch=True )
""" This example demonstrates large data sets """ from math import * from odscharts.spreadsheet import SpreadSheet mySprSht = SpreadSheet() list_of_rows = [['Angle','Sine','Cosine'], ['deg','','']] for iang in range( 3601 ): ang_deg = float(iang) / 10.0 ang = radians(ang_deg) list_of_rows.append( [ang_deg, sin(ang), cos(ang)] ) mySprSht.add_sheet('Trig_Data', list_of_rows) mySprSht.add_scatter( 'Trig_Plot', 'Trig_Data', title='Trig Functions', xlabel='Angle', ylabel='Trig Function', xcol=1, ycolL=[2,3], showMarkerL=[1,0]) mySprSht.save( filename='trig_plot', launch=True)
mySprSht.add_curve('Combo_Plot', 'Aussie_Data', xcol=1, ycolL=[2,3,4], showMarkerL=[0,], lineStyleL=[1,], lineThkL=[2,], colorL=['r','g','b']) mySprSht.add_scatter( 'Combo2_Plot', 'Aussie_Data', title='Australian and USA BMI', xlabel='Year', ylabel='Percent of Aussie Population', y2label='Percent of USA Population', xcol=1, ycolL=[2,3,4], showMarkerL=[0,], lineStyleL=[1,], lineThkL=[2,], colorL=['r','g','b']) mySprSht.add_curve('Combo2_Plot', 'USA_Data', xcol=1, ycol2L=[2,3,4], showMarker2L=[0,], lineThk2L=[2,], color2L=['r','g','b']) mySprSht.setYrange( ymin=0, ymax=80, plot_sheetname=None) mySprSht.setY2range( ymin=0, ymax=80, plot_sheetname=None) mySprSht.save( filename='bmi_index.ods', launch=True )
""" This example demonstrates a simple chart """ from odscharts.spreadsheet import SpreadSheet mySprSht = SpreadSheet() list_of_rows = [['Altitude', 'Pressure'], ['feet', 'psia'], [0, 14.7], [5000, 12.23], [10000, 10.11], [30000, 4.36], [60000, 1.04]] mySprSht.add_sheet('Alt_Data', list_of_rows) mySprSht.add_scatter('Alt_P_Plot', 'Alt_Data', title='Pressure vs Altitude', xlabel='Altitude', ylabel='Pressure', xcol=1, ycolL=[2]) mySprSht.save(filename='alt_vs_press') mySprSht.launch_application()