API

crGraphs

A module that lets you create pretty graphs with single-line function calls.

Useful constants:

  • SHOW_OUTPUT - (default = False) Set to True to see output of the functions
  • BASE_FILE_PATH - (default = “./”) File path that is pre-pended to any filePath_ parameters of the functions
  • DPI - (default = 100) DPI of created figures. Set to a higher number for a higher resolution.
  • DEBUG_LEVEL - (default = 0) O - no debug messages, 1 - some debug messages, 2 - deep debug messages

To override the constants, set them after importing crGraphs, e.g.

from pyCreeper import crGraphs;
crGaphs.DPI = 200;

Author: Lenka Pitonakova: contact@lenkaspace.net

pyCreeper.crGraphs.createBarPlot(data_, title_='', xLabel_='', yLabel_='', xTickLabels_=[], legendTitle_='', legendLabels_=[], showConfidenceIntervals_=False, showAverages_=False, averagesIgnoreZeros_=False, barWidth_=0.8, yMin_=-999999, yMax_=-999999, yTicksStep_=0, yTicksStepMultiplier_=1, filePath_='', renderFigure_=True, figure_=None, subPlot_=111)[source]

Create bars for groups next to each other, grouped by group labels.

Minimal example:

profitData = [
        [1, 2, 4, 3, 6, 8]
];

crGraphs.createBarPlot(profitData);
Parameters:
  • data_ – A 2D or a 3D list of numbers. The 0th dimension represents individual bar groups (colors). The 1st dimension represents data points along the x axis. Optional 3rd dimension is a list of values that each bar consists of. A bar then shows a median / average of that list
  • title_ – (optional, default = “”) The figure title
  • xLabel_ – (optional, default = “”) Label of the x-axis
  • yLabel_ – (optional, default = “”) Label of the y-axis
  • xTickLabels_ – (optional, default = []) A 1D list of tick labels for the x-axis.
  • legendTitle_ – (optional, defalut = “”) Text shown before legend
  • legendLabels_ – (optional, default = []) A 1D list of labels for the individual plot lines. Must be the same length as the 0th dimension of data_, i.e., each plot line must have a corresponding legendLabel
  • showConfidenceIntervals_ – (optional, default = False) A boolean that specified whether to show error bars. If True, data_ must be a 3D list
  • showAverages_ – (optional, default = False) A boolean that specifies whether to show averages instead of medians. If True, data_ must be a 3D list
  • averagesIgnoreZeros_ – (optional, default = False) If true, only non-zero values are considered when calculating the averages
  • yMin_ – (optional, default = INVALID_VALUE) Minimum value shown on the y-axis. If set to INVALID_VALUE, y-axis is displayed to fit the data
  • yMax_ – (optional, default = INVALID_VALUE) Maximum value shown on the y-axis. If set to INVALID_VALUE, y-axis is displayed to fit the data
  • yTicksStep_ – (optional, default = 0) A number that represents the different between each tick on the y-axis. If set to 0, y-axis is displayed to fit the data
  • yTicksStepMultiplier_ – (optional default = 1) A number by which each tick on the y axis is multiplied by.
  • filePath_ – (optional, default = “”) If not empty, the figure will be saved to the file path specified. If empty, the figure will be displayed on screen instead.
  • renderFigure_ – (optional, default = True) If false, the figure will not be displayed or printed. Set to False when putting multiple figures together via the figure_ parameter.
  • figure_ – (optional, default = None) If not None, the figure will be created into this figure (pylab.figure)
  • subPlot_ – (optional, default = 111) The subplot id of where to place the graph to
Returns:

pylab.figure for the plot

pyCreeper.crGraphs.createFigure(size_, title_='', figure_=None, subPlot_=111, xLabel_='', yLabel_='', xStretchMultiply_=1.2, yStretchMultiply_=1.2)[source]

A helper function that creates a figure.

Parameters:
  • size_ – The figure size
  • title_ – (optional, default = “”) The figure title
  • figure_ – (optional, default = None) If not None, the figure will be created into this figure (pylab.figure)
  • subPlot_ – (optional, default = 111) The subplot id of where to place the graph to
  • xLabel_ – (optional, default = “”) Label of the x-axis
  • yLabel_ – (optional, default = “”) Label of the y-axis
  • xStretchMultiply_ – (optional, default = 1.2) By how much to stretch the plot inside the figure in x direction. Enter 1.0 to leave the plot as is.
  • yStretchMultiply_ – (optional, default = 1.2) By how much to stretch the plot inside the figure in y direction. Enter 1.0 to leave the plot as is.
  • xOffset_ – (optional, default = 0) Horizontal offset of the plot
  • yOffset_ – (optional, default = 0) Vertical offset of the plot
Returns:

(pylab.figure, pylab.ax)

pyCreeper.crGraphs.createLinePlot(data_, title_='', xLabel_='', yLabel_='', xTickLabels_=[], xTickLabelPositions_=[], legendTitle_='', legendLabels_=[], showBoxPlots_=False, showConfidenceIntervals_=False, showAverages_=False, averagesIgnoreZeros_=False, doWilcoxon_=False, xMin_=-999999, xMax_=-999999, xAxisGroupSize_=0, yMin_=-999999, yMax_=-999999, yTicksStep_=0, yTicksStepMultiplier_=1, useBoxPlotPadding_=False, filePath_='', renderFigure_=True, figure_=None, subPlot_=111)[source]

Create one of a plot with a single or multiple lines. Optionally, each data point can have error bars or box plots around it.

Minimal example:

profitData = [
        [1, 2, 4, 3, 6, 8]
];

crGraphs.createLinePlot(profitData);
Parameters:
  • data_ – A 2D or a 3D list of numbers. The 0th dimension represents individual lines. The 1st dimension represents data points on the line, ordered by x coordinate. Optional 3rd dimension is a list of values that each data point consists of. A data point is then a median of that list
  • title_ – (optional, default = “”) The figure title
  • xLabel_ – (optional, default = “”) Label of the x-axis
  • yLabel_ – (optional, default = “”) Label of the y-axis
  • xTickLabels_ – (optional, default = []) A 1D list or numpy.array of tick labels for the x-axis. Make this a numpy.array when there are too many data points and x-axis values can be shown as numbers.
  • xTickLabelPositions_ – (optional, default numpy.array()) A 1D list of positions on x-axis where ticks should be shown. Can be used e.g. when there are too many data points than xTickLabels and xTickLabels needs to show string values.
  • legendTitle_ – (optional, defalut = “”) Text shown before legend
  • legendLabels_ – (optional, default = []) A 1D list of labels for the individual plot lines. Must be the same length as the 0th dimension of data_, i.e., each plot line must have a corresponding legendLabel
  • showBoxPlots_ – (optional, default = False) A boolean that specified whether to show box plots around data points. If True, data_ must be a 3D list
  • showConfidenceIntervals_ – (optional, default = False) A boolean that specified whether to show error bars around data points. If True, data_ must be a 3D list
  • showAverages_ – (optional, default = False) A boolean that specifies whether to show averages instead of medians as data points. If True, data_ must be a 3D list
  • averagesIgnoreZeros_ – (optional, default = False) If true, only non-zero values are considered when calculating the averages
  • doWilcoxon_ – (optional, default = False) A boolean that specified whether to perform Wilcoxon signed-rank test between 2 plot lines. If True, the * notation is used next to a tick label on the x-axis where there is significant difference with p=0.05. The ** notation is used when there is a significant different with p=0.01. This test can only be performed when data_ has length of 2 and is a 3D list, i.e., if it containts data for 2 plot lines and each data point represents a list of values
  • xMin_ – (optional, default = INVALID_VALUE) Minimum value shown on the x-axis. If set to INVALID_VALUE, x-axis is displayed to fit the data
  • xMax_ – (optional, default = INVALID_VALUE) Maximum value shown on the x-axis. If set to INVALID_VALUE, x-axis is displayed to fit the data
  • xAxisGroupSize_ – (optional, default = 0) The number of data points that are joined by lines when they are next to each other on the x-axis. If set to 0, all data points are joined together. If set to > 0, groups of data points appear, with no joining lines between data points from different groups.
  • yMin_ – (optional, default = INVALID_VALUE) Minimum value shown on the y-axis. If set to INVALID_VALUE, y-axis is displayed to fit the data
  • yMax_ – (optional, default = INVALID_VALUE) Maximum value shown on the y-axis. If set to INVALID_VALUE, y-axis is displayed to fit the data
  • yTicksStep_ – (optional, default = 0) A number that represents the different between each tick on the y-axis. If set to 0, y-axis is displayed to fit the data
  • yTicksStepMultiplier_ – (optional default = 1) A number by which each tick on the y axis is multiplied by.
  • useBoxPlotPadding_ – (optional, default = False) Set this to true to add horizontal padding to the plot that matches padding of a box plot. E.g. when showing single data points next to similar box plot graphs, it might be desirable to keep the plot paddings the same.
  • filePath_ – (optional, default = “”) If not empty, the figure will be saved to the file path specified. If empty, the figure will be displayed on screen instead.
  • renderFigure_ – (optional, default = True) If false, the figure will not be displayed or printed. Set to False when putting multiple figures together via the figure_ parameter.
  • figure_ – (optional, default = None) If not None, the figure will be created into this figure (pylab.figure)
  • subPlot_ – (optional, default = 111) The subplot id of where to place the graph to
Returns:

pylab.figure for the plot

pyCreeper.crGraphs.createMatrixPlot(data_=[[], []], title_='', xLabel_='', yLabel_='', xTickLabels_=[], yTickLabels_=[], colorBarLabel_='', minValue_=-999999, maxValue_=-999999, annotateValues_=False, annotationStringAfter_='', annotationValues_=[[], []], roundAnnotatedValues_=False, filePath_='', renderFigure_=True, figure_=None, subPlot_=111)[source]

Create 2D matrix plot where color gradient represents value on a 3rd dimension.

Note: The figure size is set to (getStyle().figureSize[0]-1, getStyle().figureSize[1]+1) to get proper paddings and to match other figure types as close as possible.

Minimal example:

performanceData = [
                [12,11,10,9],
                [11,10,7,6],
                [9,8,6,5],
                ];
crGraphs.createMatrixPlot(performanceData);
Parameters:
  • data_ – a 2D list of values, where the 0th dimension runs along the x axis and the 1st dimension along y axis, so [0,0] in the list specified a value for the bottom left square
  • title_ – (optional, default = “”) The figure title
  • xLabel_ – (optional, default = “”) Label of the x-axis
  • yLabel_ – (optional, default = “”) Label of the y-axis
  • xTickLabels_ – (optional, default = []) Labels of the individual ticks of the x-axis. If empty, values 0-N are displayed
  • yTickLabels_ – (optional, default = []) Labels of the individual ticks of the y-axis. If empty, values 0-N are displayed
  • colorBarLabel_ – (optional, default = “”) Label of color bar, displayed vertically
  • minValue_ – (optional, default = INVALID_VALUE) Minimum float value that the color map considers. If set to INVALID_VALUE, the value is automatically calculated from data_
  • maxValue_ – (optional, default = INVALID_VALUE) Maximum float value that the color map considers. If set to INVALID_VALUE, the value is automatically calculated from data_
  • annotateValues_ – (optional, default = False) If True, data values will be displayed in the matrix plot
  • annotationStringAfter_ – (optional, default = “”) A string to append after each annotation value
  • annotationValues_ – (optional, default = [[],[]]) A 2D list of annotations in the matrix plot. If non-empty, must have the same dimensions as data_
  • roundAnnotatedValues_ – (optional, default = False) If True and if annotationValues_ is empty, annotation numbers will be rounded
  • filePath_ – (optional, default = “”) If not empty, the figure will be saved to the file path specified. If empty, the figure will be displayed on screen instead.
  • renderFigure_ – (optional, default = True) If false, the figure will not be displayed or printed. Set to False when putting multiple figures together via the figure_ parameter.
  • figure_ – (optional, default = None) If not None, the figure will be created into this figure (pylab.figure)
  • subPlot_ – (optional, default = 111) The subplot id of where to place the graph to
Returns:

pylab.figure for the plot

pyCreeper.crGraphs.createPieChart(data_=[], itemLabels_=[], title_='', itemColors_=[], showActualVals_=True, showPercentageVals_=False, showShadow_=False, filePath_='', renderFigure_=True, figure_=None, subPlot_=111)[source]

Create a pie chart.

Note: If the figure is rendered (renderFigure_ = True), the figure size is close to a square, with the width and height as specified in the style’s figureSize.

Minimal example:
expenseCategories = ["Rent", "Food", "Travel", "Fun"];
expenses = [1000, 300, 500, 250];
crGraphs.createPieChart(expenses, expenseCategories);
Parameters:
  • data_ – A 1D list of values
  • itemLabels_ – A 1D list of value labels. Must be the same length as data_
  • title_ – (optional, default = “”) The figure title
  • showActualVals_ – (optional, default = True) Boolean whetehr to show data values in the pie parts
  • showPercentageVals_ – (optional, default = False) Boolean whether to show percentages in the pie parts
  • showShadow_ – (optional, default = False) Boolean whether to show shadow underneath the pie
  • filePath_ – (optional, default = “”) If not empty, the figure will be saved to the file path specified. If empty, the figure will be displayed on screen instead.
  • renderFigure_ – (optional, default = True) If false, the figure will not be displayed or printed. Set to False when putting multiple figures together via the figure_ parameter.
  • figure_ – (optional, default = None) If not None, the figure will be created into this figure (pylab.figure)
  • subPlot_ – (optional, default = 111) The subplot id of where to place the graph to
Returns:

pylab.figure for the plot

pyCreeper.crGraphs.getBrokenLinePlotParameters(yMin_, brokenLineY_, yMax_, brokenLinePlotHeightPercentage_=60)[source]

Get y-axis parameters of two plots, bottom and top, that can be combined together into a broken line plot.

Parameters:
  • yMin – Minimum value shown on the y-axis.
  • brokenLineY – Y-axis value at which the broken line will be drawn
  • yMax – Maximum value shown on the y-axis.
  • brokenLinePlotHeightPercentage – (optional, default = 60) The percentage (20-80) of the plot’s height at which the broken line will be drawn
Returns:

(bottom plot y min, bottom plot y max, top plot y min, top plot y max)

pyCreeper.crGraphs.getStyle()[source]
Returns:A pyCreeper.crGraphStyle.crGraphStyle instance.
pyCreeper.crGraphs.renderFigure(figure_, filePath_='', renderFigure_=True)[source]

A helper function that performs the current pylab’s figure rendering into a file or on screen

Parameters:
  • filePath_ – (optional, default = “”) If not empty, the figure will be saved to the file path specified. If empty, the figure will be displayed on screen instead.
  • renderFigure_ – (optional, default = True) If false, the figure will not be displayed or printed.
pyCreeper.crGraphs.replaceInvalidWithDefaultValue(value_, defaultValue_)[source]

A helper function used when checking parameter values. If the parameter value (value_) is crGraphs.INVALID_VALUE, returns a specified defaultValue_ instead.

Parameters:
  • value_ – the value
  • defaultValue_ – the value to use if value_ == INVALID_VALUE
pyCreeper.crGraphs.setFigureAxisLimits(ax_, minDataValue_, maxDataValue_, xMin_=-999999, xMax_=-999999, yMin_=-999999, yMax_=-999999, yTicksStep_=0, yTicksStepMultiplier_=1)[source]
pyCreeper.crGraphs.setStyle(style_)[source]

Set the style.

Parameters:style – A pyCreeper.crGraphStyle.crGraphStyle instance
pyCreeper.crGraphs.setTickLabels(ax_, data_, xTickLabels_, minSpacingBetweenXLabels_)[source]

crGraphStyle

class pyCreeper.crGraphStyle.GRID_TYPE[source]

An enumeration.

FULL = 1
HORIZONTAL = 2
MAJOR = 4
MAJOR_HORIZONTAL = 5
MAJOR_VERTICAL = 6
MINOR = 7
MINOR_HORIZONTAL = 8
MINOR_VERTICAL = 9
NONE = 0
VERTICAL = 3
class pyCreeper.crGraphStyle.LEGEND_POSITION[source]

An enumeration.

BEST = 'best'
CENTER = 'center'
CENTER_LEFT = 'center left'
CENTER_RIGHT = 'center right'
LOWER_CENTER = 'lower center'
LOWER_LEFT = 'lower left'
LOWER_RIGHT = 'lower right'
NONE = 'none'
RIGHT = 'right'
UPPER_CENTER = 'upper center'
UPPER_LEFT = 'upper left'
UPPER_RIGHT = 'upper right'
class pyCreeper.crGraphStyle.crGraphStyle[source]

Encapsulates styling that pyCreeper.crData uses.

Author: Lenka Pitonakova: contact@lenkaspace.net

Minimal example:

myStyle = pyCreeper.crGraphStyle.crGraphStyle();
style.lineWidth = 3;
pyCreeper.crGraphs.setStyle(style);

# now use pyCreeper.crGraphs functions and the new style will be applied
boxPlotLineWidth

Box plot line width. Default = 2

boxPlotWidth

Box plot width. Default = crGraphs.INVALID_VALUE If equal to crGraphs.INVALID_VALUE, box plot width is calculated automatically.

colorMap

A python.cm instance to use for the matrix plots. Default = pyplot.cm.get_cmap(“summer”)

colors

A 1D list of colors for the plot lines. Default = [‘b’,’r’,’g’,’c’,’k’]

figureSize

The figure size. Default = (12,6)

getMatplotlibGridSettings()[source]

Get matplotlib strings that should be used for matplotlib’s ax.grid(which=gridWhich, axis=gridAxis)

Returns:[gridAxis, gridWhich]
gridType

A GRID_TYPE enum member. Default = GRID_TYPE.FULL

labelFontSize

Font size of the axis and color bar labels. Default = 25

legendFontSize

Font size of the legend. Default = 25

legendPosition

A LEGEND_POSITION enum member. Default = LEGEND_POSITION.BEST

lineStyles

A 1D list of line styles for the plot lines. If a corresponding style for a plot line is not specified, a solid line is displayed.

lineWidth

Line width. Default = 2

markerSize

Size of markers. Default = 12

markers

A 1D list of markers for the plot lines. Default = [‘bs-‘,’rs-‘,’gs-‘,’cs-‘,’ks-‘]

numOfLegendColumns

Number of columns in the legend. Default = 2

reset()[source]

Set everything to defaults

tickFontSize

Font size of axis ticks and of values inside the plot. Default = 17

titleFontSize

Font size of the title. Default = 25

wereColorsSetByUser = False
xLabelPadding

Padding between the X axis label and markers. Default = 20

xOffset

Horizontal offset of the plot. Note this doesn’t work for matrix plots. Default = 0.0

yLabelPadding

Padding between the Y axis label and markers. Default = 20

yOffset

Vertical offset of the plot. Note this doesn’t work for matrix plots. Default = 0.0

crData

A module that lets you read data from files and manipulate data, mainly for use by crGraphs

Author: Lenka Pitonakova: contact@lenkaspace.net

pyCreeper.crData.addUniqueElementToList(element_, array_, debugMessage_='', printDebug_=False)[source]
pyCreeper.crData.compressList(data_, timeBinLength_, useAverages_=True, discardZerosFromAverages_=False, debug_=False)[source]

Compress a list by aggregating data into bins.

For example:

realTimeData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

compressedData = pyCreeper.crData.compressList(realTimeData,3)
print(compressedData)

[out:] [2.0, 5.0, 8.0, 3.3333333333333335]
Parameters:
  • data – 2D array
  • timeBinLength – length of one time bin (number of time bins of the uncompressed data)
  • useAverages – (optional, default = True) If true, the compressed value in each bin will be an average of values of the uncompressed data. If false, sum of uncompressed data values will be used.
  • discardZerosFromAverages – (optional, default = False) If true, averages calculated when useAverages_=True do not take 0s into account
  • debug – (optional, default = False) If true, extra debug info is printed
Returns:

A compressed list

pyCreeper.crData.getAverageOfAList(list_, ignoreZeros_=False, nullValue_=0)[source]

Get average value of a list of values.

Parameters:
  • list – The list
  • ignoreZeros – (optional, default = False) If true, only non-zero values are considered when calculating the average
  • nullValue – (optional, default = 0) Value that should be returned when the list_ is empty

:return number

pyCreeper.crData.getListByFlippingColumnsAndRows(array_)[source]

Return array that has rows with columns flipped

Parameters:array – 2D array of data
Returns:2D array of data
pyCreeper.crData.getListColumnAsArray(array_, columnId_, valueMultiplier_=1)[source]

Returns a 1d list filled with values of a column of a specified array. Also multiplies each value by valueMultiplier_.

Parameters:
  • array – 2D array of data
  • columnId – id of the column to retrieve (0-based)
  • valueMultiplier – (optional, default=1) A value by which to multiply each element in the selected column

:return 1D array with selected data

pyCreeper.crData.getMaxValueInAList(list_)[source]

Get a maximum value from an N-dimensional list of numbers

Parameters:list – The list
Returns:number
pyCreeper.crData.getMedianOfAList(list_, ignoreZeros_=False)[source]

Get median value of a list of values.

Parameters:
  • list – The list
  • ignoreZeros – (optional, default = False) If true, only non-zero values are considered when looking for a median

:return number

pyCreeper.crData.getMinValueInAList(list_)[source]

Get a minimum value from an N-dimensional list of numbers

Parameters:list – The list
Returns:number
pyCreeper.crData.getNumberOfListDimensions(list_)[source]

Return the number of dimensions of an N-dimensional list by recursively going through the list until a non-list or an empty list is found in one of the dimensions.

To correctly measure dimensionality, it is recommended that the list doesn’t contain empty sublists and that all elements (apart from those in the highest dimension) are of the same type.

Parameters:list – The list
Returns:int : The number of dimensions
pyCreeper.crData.removeElementFromList(element_, array_, debugMessage_='', printDebug_=False)[source]

crFiles

pyCreeper.crFiles.fileToArray(filePath_, separator_=', ', ignoreFirstRow_=False, startRow_=1, endRow_=-1)[source]

Store data from a file in a 2D array with format array[rows][columns]. For example, if a file looks like this:

time,column1,column2
1,20,30
2,25,60

The resulting data array will be

[[1,20,30],
 [2,25,60]]
Parameters:
  • filePath – Full path to the file
  • separator – (optional, default = “,”) String that separates values in a row
  • ignoreFirstRow – (optional, default = False) If True, the first row of the file will not be parsed. Useful when the first row contains column descriptions
  • startRow – (optional, default = 1) The first row that will be read
  • endRow – (optional, default = -1) When >=0, only rows up to endRow_ will be read
Returns:

A 2D array

crHelpers

A module that lets you create pretty graphs with single-line function calls

Author: Lenka Pitonakova: contact@lenkaspace.net

pyCreeper.crHelpers.checkListHasAtLeastLengthOfList(list1_, list2_)[source]

Raises a ValueError if list 1 is shorter than list 2.

Parameters:
  • list1_ – List 1
  • list2_ – List 2 to compare length of list1_ to
pyCreeper.crHelpers.checkListsHaveTheSameLength(list1_, list2_)[source]

Raises a ValueError if 2 lists are not of the same length.

Parameters:
  • list1_ – List 1
  • list2_ – List 2
pyCreeper.crHelpers.checkVariableBetweenValues(variable_, valueMin_, valueMax_)[source]

Check if valueMin_ <= variable_ <= valueMax_

Parameters:
  • variable_ – The value of the variable
  • valueMin_ – Minimum value the variable can take
  • valueMax_ – Maximum value the variable can take
pyCreeper.crHelpers.checkVariableDataType(variable_, expectedDataType_)[source]

Check if a variable has a specified data type. If not, raises a TypeError.

Parameters:
  • variable_ – The value of a variable
  • expectedDataType_ – The desired data type. Can either be one type or a list of types
pyCreeper.crHelpers.checkVariableGreaterThanAnother(variable1_, variable2_)[source]

Check if a variable is greater than another. If not, raises a TypeError.

Parameters:
  • variable1_ – The value of variable 1
  • variable2_ – The value of variable 2
pyCreeper.crHelpers.checkVariableIsList(variable_, dimensions_=1, nonEmpty_=False)[source]

Raises a TypeError if a variable is not a list.

Parameters:
  • variable_ – The value of a variable
  • dimensions_ – (optional, default=1) The number of dimensions of the array
  • nonEmpty_ – (optional, default=False) If true, the list must be non-empty
pyCreeper.crHelpers.getVariableNamePassedAsParameter(parameterNumber_=1)[source]

Get the name of the variable that was passed as the first parameter to a function that called this function.

Parameters:parameterOrder – (optional, default = 1) Parameter number (1-X)
Returns:String variable name