ODSCharts Code Functions

exception odscharts.spreadsheet.MySheetNameError(msg)

Custom exception handler for duplicate sheet names

class odscharts.spreadsheet.SpreadSheet

Creates OpenDocument Spreadsheets with charts for Microsoft Excel, LibreOffice and OpenOffice

add_curve(plot_sheetname, data_sheetname, xcol=1, ycolL=None, ycol2L=None, showMarkerL=None, showMarker2L=None, showLineL=None, showLine2L=None, lineThkL=None, lineThk2L=None, lineStyleL=None, lineStyle2L=None, colorL=None, color2L=None, labelL=None, label2L=None)

Use data from “data_sheetname” to add a plot or plots to scatter plot on page “plot_sheetname”.

Most of the inputs are exactly like the “add_scatter” method.

Assume index into columns is “1-based” such that column “A” is 1, “B” is 2, etc.

NOTE: marker color is NOT supported in Excel from ODS format. Markers will appear, but will be some other default color. For this reason, ODSCharts uses Excel default color list unless the user overrides them with colorL or color2L.

Parameters:
  • plot_sheetname (str or unicode) – Name of the plot’s tabbed window in Excel,LibreOffice or OpenOffice

  • data_sheetname (str or unicode) – Name of the data’s tabbed window in Excel, LibreOffice or OpenOffice

  • xcol (int) – 1-based column index on data sheet of X Axis data (default==1)

  • ycolL (None or int list) – List of 1-based column indeces on data sheet of Primary Y Axis data (default==None)

  • ycol2L (None or int list) – List of 1-based column indeces on data sheet of Secondary Y Axis data (default==None)

  • showMarkerL (None or bool list) – List of boolean values indicating marker or no-marker for ycolL data (default==None)

  • showMarker2L (None or bool list) – List of boolean values indicating marker or no-marker for ycol2L data (default==None)

  • showLineL (None or bool list) – List of boolean values indicating line or no-line for ycolL data (default==None)

  • showLine2L (None or bool list) – List of boolean values indicating line or no-line for ycol2L data (default==None)

  • lineThkL (list of float) – List of thickness values for primary y axis curves. If the list is not defined, then the thickness is set to “0.8mm”. For example, lineThkL=[0.5, 1, 2] gives thin, about normal and thick lines. (Units==”mm”)(default==None)

  • lineThk2L (list of float) – List of thickness values for secondary y axis curves If the list is not defined, then the thickness is set to “0.8mm”. For example, lineThkL=[0.5, 1, 2] gives thin, about normal and thick lines. (Units==”mm”)(default==None)

  • lineStyleL (None or int list) – List of line style values to use for ycolL curves. Any curve not explicitly set will use a solid line. (see http://odscharts.readthedocs.org/en/latest/examples.html for details) (default==None)

:keyword lineStyle2L:List of line style values to use for ycol2L curves. Any curve not explicitly set will use a solid line. (see http://odscharts.readthedocs.org/en/latest/examples.html for details) (default==None) :type lineStyle2L: None or int list

Parameters:
  • colorL (None or str list) – List of color values to use for ycolL curves. Format is “#FFCC33”. Any curve not explicitly set will use Excel default colors (default==None)

  • color2L (None or str list) – List of color values to use for ycol2L curves. Format is “#FFCC33”. Any curve not explicitly set will use Excel default colors (default==None)

  • labelL (None or str list) – Not yet implemented (default==None)

  • label2L (None or str list) – Not yet implemented (default==None)

Returns:

None

Return type:

None

add_scatter(plot_sheetname, data_sheetname, title='', xlabel='', ylabel='', y2label='', xcol=1, logx=False, logy=False, log2y=False, excel_colors=True, ycolL=None, ycol2L=None, showMarkerL=None, showMarker2L=None, showLineL=None, showLine2L=None, showUnits=True, lineThkL=None, lineThk2L=None, lineStyleL=None, lineStyle2L=None, colorL=None, color2L=None, labelL=None, label2L=None)

Add a scatter plot to the spread sheet.

Use data from “data_sheetname” to create “plot_sheetname” with scatter plot.

Assume index into columns is “1-based” such that column “A” is 1, “B” is 2, etc.

NOTE: marker color is NOT supported in Excel from ODS format. Markers will appear, but will be some other default color. For this reason, ODSCharts uses Excel default color list unless the user overrides them with colorL or color2L.

Parameters:
  • plot_sheetname (str or unicode) – Name of the plot’s tabbed window in Excel, LibreOffice or OpenOffice

  • data_sheetname (str or unicode) – Name of the data’s tabbed window in Excel, LibreOffice or OpenOffice

  • title (str or unicode) – Title of the plot as displayed in Excel, LibreOffice or OpenOffice (default==’’)

  • xlabel (str or unicode) – X Axis label as displayed in Excel, LibreOffice or OpenOffice (default==’’)

  • ylabel (str or unicode) – Primary Y Axis label as displayed in Excel, LibreOffice or OpenOffice (default==’’)

  • y2label (str or unicode) – Secondary Y Axis Label as displayed in Excel, LibreOffice or OpenOffice (default==’’)

  • xcol (int) – 1-based column index on data sheet of X Axis data (default==1)

  • ycolL (None or int list) – List of 1-based column indeces on data sheet of Primary Y Axis data (default==None)

  • ycol2L (None or int list) – List of 1-based column indeces on data sheet of Secondary Y Axis data (default==None)

  • showMarkerL (None or bool list) – List of boolean values indicating marker or no-marker for ycolL data (default==None)

  • showMarker2L (None or bool list) – List of boolean values indicating marker or no-marker for ycol2L data (default==None)

  • showLineL (None or bool list) – List of boolean values indicating line or no-line for ycolL data (default==None)

  • showLine2L (None or bool list) – List of boolean values indicating line or no-line for ycol2L data (default==None)

  • lineThkL (list of float) – List of thickness values for primary y axis curves. If the list is not defined, then the thickness is set to “0.8mm”. For example, lineThkL=[0.5, 1, 2] gives thin, about normal and thick lines. (Units==”mm”)(default==None)

  • lineThk2L (list of float) – List of thickness values for secondary y axis curves If the list is not defined, then the thickness is set to “0.8mm”. For example, lineThkL=[0.5, 1, 2] gives thin, about normal and thick lines. (Units==”mm”)(default==None)

  • logx (bool) – Flag for X Axis type. True=log, False=linear (default==False)

  • logy (bool) – Flag for Primary Y Axis type. True=log, False=linear (default==False)

  • log2y (bool) – Flag for Secondary Y Axis type. True=log, False=linear (default==False)

  • showUnits (bool) – Flag to control units display. True=show units on axes, False=show labels only (default==True)

  • excel_colors (bool) – Flag to control default color palette. True=use Excel colors, False=use custome colors.

  • lineStyleL (None or int list) – List of line style values to use for ycolL curves. Any curve not explicitly set will use a solid line. (see http://odscharts.readthedocs.org/en/latest/examples.html for details) (default==None)

:keyword lineStyle2L:List of line style values to use for ycol2L curves. Any curve not explicitly set will use a solid line. (see http://odscharts.readthedocs.org/en/latest/examples.html for details) (default==None) :type lineStyle2L: None or int list

Parameters:
  • colorL (None or str list) – List of color values to use for ycolL curves. Format is “#FFCC33”. Any curve not explicitly set will use Excel default colors (default==None)

  • color2L (None or str list) – List of color values to use for ycol2L curves. Format is “#FFCC33”. Any curve not explicitly set will use Excel default colors (default==None)

  • labelL (None or str list) – Not yet implemented (default==None)

  • label2L (None or str list) – Not yet implemented (default==None)

Returns:

None

Return type:

None

add_sheet(data_sheetname, list_of_rows)

Create a new sheet in the spreadsheet with “data_sheetname” as its name.

the list_of_rows will be placed at “A1” and should be:
  • row 1 is labels

  • row 2 is units

  • row 3 through N is float or string entries

for example: list_of_rows =

[['Altitude','Pressure','Temperature'],
['feet','psia','degR'],
[0, 14.7, 518.7],
[5000, 12.23, 500.8],
[10000, 10.11, 483.0],
[60000, 1.04, 390]]
Parameters:
  • data_sheetname (str or unicode) – Name of the data’s tabbed window in Excel, LibreOffice or OpenOffice

  • list_of_rows (list) – the list_of_rows will be placed at “A1” and should be: - row 1 is labels - row 2 is units - row 3 through N is float or string entries

Returns:

None

Return type:

None

launch_application()

Will launch Excel, LibreOffice or Openoffice using “os.startfile” or “open” or “xdg-open” depending on the platform.

ONLY WORKS IF file has been saved.

meta_time()

Return time string in meta data format

save(filename='my_chart.ods', launch=False)

Saves SpreadSheet to an ods file readable by Microsoft Excel, LibreOffice or OpenOffice.

If the launch flag is set, will launch Excel, LibreOffice or Openoffice using “os.startfile” or “open” or “xdg-open” depending on the platform.

Parameters:
  • filename (str or unicode) – Name of ods file to save (default==’my_chart.ods’)

  • launch (bool) – If True, will launch Excel, LibreOffice or OpenOffice (default==False)

Returns:

None

Return type:

None

setAxisRange(axis_name, min_val=None, max_val=None, plot_sheetname=None)

Generic routine used by setXrange, setYrange and setY2range. (Not called by User)

Set the Axis range of the named plot to min_val, max_val.

  • If no plot_sheetname is provided, use the latest plot (if any).

  • If no min_val is provided, ignore it.

  • If no max_val is provided, ignore it.

setXrange(xmin=None, xmax=None, plot_sheetname=None)

Set the X range of the named plot to xmin, xmax.

  • If no plot_sheetname is provided, use the latest plot (if any).

  • If no min_val is provided, ignore it.

  • If no max_val is provided, ignore it.

Parameters:
  • xmin (float or None) – Minimum value on X Axis (default==None)

  • xmax (float or None) – Maximum value on X Axis (default==None)

  • plot_sheetname (None or str or unicode) – (default==None)

Returns:

None

Return type:

None

setY2range(ymin=None, ymax=None, plot_sheetname=None)

Set the Y2 range of the named plot to ymin, ymax.

  • If no plot_sheetname is provided, use the latest plot (if any).

  • If no min_val is provided, ignore it.

  • If no max_val is provided, ignore it.

Parameters:
  • ymin (float or None) – Minimum value on Secondary Y Axis (default==None)

  • ymax (float or None) – Maximum value on Secondary Y Axis (default==None)

  • plot_sheetname (None or str or unicode) – (default==None)

Returns:

None

Return type:

None

setYrange(ymin=None, ymax=None, plot_sheetname=None)

Set the Y range of the named plot to ymin, ymax.

  • If no plot_sheetname is provided, use the latest plot (if any).

  • If no min_val is provided, ignore it.

  • If no max_val is provided, ignore it.

Parameters:
  • ymin (float or None) – Minimum value on Primary Y Axis (default==None)

  • ymax (float or None) – Maximum value on Primary Y Axis (default==None)

  • plot_sheetname (None or str or unicode) – (default==None)

Returns:

None

Return type:

None

odscharts.spreadsheet.zipfile_insert(zipfileobj, filename, data)

Create a file named filename, in the zip archive. “data” is the UTF-8 string that is placed into filename.

(Not called by User)