SLiCAPplots.py¶
SLiCAP module with plot functions.
Imported by the module SLiCAPhtml.py
-
LTspiceData2Traces(txtFile)¶ Generates a dictionary with traces (key = label, value = trace object) from LTspice plot data (saved as .txt file).
Parameters: txtFile (str) – Name of the text file stored in the ini.txtPath directory Returns: Dictionary with key-value pairs: - key: str: label of the trace
- value: SLiCAPplots.trace trace object
Return type: dict
-
class
axis(title)¶ Axis prototype.
Parameters: title (str) – Title of the axis. The title will be placed on top of the axis. -
makeTraceDict()¶ Returns a dict with data of all the traces on the axis.
Returns: dictionary with key-value pairs: - key: str label of the trace
- value: SLiCAPplots.trace trace object
Return type: dict
-
polar= None¶ (bool) True if a polar axis is required. Defaults to False.
-
text= None¶ Text ([int, int, str]) with relative plot position: [<xPos>, <yPos>, <text>]. Defaults to [0, 0, ‘’].
-
title= None¶ Title (str) of the axis, will be placed on top of the axis
-
traces= None¶ List with SLiCAPplots.trace objects to be plotted on this axis: [<trace1>(,<trace2>,…,<traceN>)]. Defaults to [].
-
xLabel= None¶ Label (str) for the x-axis, e.g. ‘frequency [Hz]’. Defaults to False.
-
xLim= None¶ Limits (list) for the x-scale: [<xMin>, <xMax>]. Defaults to [].
-
xScale= None¶ Scale (str) for the x-axis can be ‘lin’ or ‘log’. Defaults to ‘lin’.
-
xScaleFactor= None¶ Scale factor (str) for the x-scale; e.g. M for 1E6. Defaults to ‘’.
-
yLabel= None¶ Label (str) for the x-axis, e.g. ‘voltage [V]’. Defaults to False.
-
yLim= None¶ Limits (list) for the y-scale: [<yMin>, <yMax>]. Defaults to [].
-
yScale= None¶ Scale (str) for the y-axis can be ‘lin’ or ‘log’. Defaults to ‘lin’.
-
yScaleFactor= None¶ Scale factor (str) for the y-scale; e.g. M for 1E6. Defaults to ‘’.
-
-
csv2traces(csvFile)¶ Generates a dictionary with traces (key = label, value = trace object) from data from a csv file. The CSV file should have the following structure:
x0_label, y0_label, x1_label, y1_label, … x0_0 , y0_0 , x1_0 , y1_0 , … x0_1 , y0_1 , x1_1 , y1_1 , … … , … , … , … , …
The traces will be named with their y label.
Parameters: csvFile (str) – name of the csv file (in the ini.csvPath directory) Returns: dictionary with key-value pairs: - key: str: label of the trace
- value: SLiCAPplots.trace trace object
Return type: dict
-
defaultsPlot()¶ Applies default settings for plots.
-
class
figure(fileName)¶ Prototype SLiCAP figure object.
Parameters: fileName (str) – Name of the file for saving the figure. -
axes= None¶ List with SLiCAPplots.axis objects to be plotted on this figure. Defaults to [].
-
axisHeight= None¶ Relative height (int, float) of a single axis. Defaults to ini.figureAxisHeight.
To do: absolute measures in inch or cm.
-
axisWidth= None¶ Relative width (int, float) of a single axis. Defaults to ini.figureAxisWidth.
To do: absolute measures in inch or cm.
-
fileName= None¶ File name of the figure. Defaults to: fileName + ‘.’ + ini.figureFileType.
-
fileType= None¶ Graphic file type (str) for saving the figure. Defaults to fileName
-
plot()¶ Creates the figure, displays it if SLiCAPplots.figure.show == True and saves it to disk.
-
show= None¶ (bool) if ‘True’ the figure will be displayed with the method SLiCAPplots.figure.plot(). Defaults to [].
-
-
plot(fileName, title, axisType, plotData, xName='', xScale='', xUnits='', yName='', yScale='', yUnits='', show=False)¶ Plots x-y data, or multiple pairs of x-y data.
Parameters: - fileName (str) – Name of the file for saving it to disk.
- title (str) – Title of the figure.
- axisType (str) – Type of axis: ‘lin’, ‘log’, ‘semilogx’, ‘semilogy’ or ‘polar’.
- plotData (dict, SLiCAPplots.trace) –
dictionary with key-value pairs or dictionary with traces
- key: str label for the trace
- value:
- list [<xData>, <yData>]
- xData: list: x values
- yData: list: y values
- SLiCAPplots.trace object
- list [<xData>, <yData>]
- xName (str) – Name of the variable to be plotted along the x axis. Defaults to ‘’.
- xScale (str) – Scale factor of the x axis variable. Defaults to ‘’.
- xUnits (str) – Units of the x axis variable. Defaults to ‘’.
- yName – Name of the variable to be plotted along the y axis. Defaults to ‘’.
- yScale (str) – Scale factor of the y axis variable. Defaults to ‘’.
- yUnits (str) – Units of the y axis variable. Defaults to ‘’.
- show (bool) – If ‘True’ the plot will be shown in the workspace.
Returns: fig
Return type:
-
plotPZ(fileName, title, results, xmin=None, xmax=None, ymin=None, ymax=None, xscale='', yscale='', show=False)¶ Creates a pole-zero scatter plot.
If parameter stepping of the instruction is enabled, a root locus is drawn with the parameter as root locus variable.
In such cases special begin end endpoint markers are used:
- poles begin of root locus: ‘x’
- poles end of root locus: ‘+’
- zeros begin of root locus: ‘o’
- zeros end of root locus: ‘square’
The root locus itself is drawn with dots for each position of a pole or zero.
Results of multiple analysis can be combined in one plot by putting them in a list.
The type of the axis is ‘lin’.
Parameters: - fileName (str) – Name of the file for saving it to disk.
- title (str) – Title of the figure.
- results (list, SLiCAPprotos.allResults) – Results of the execution of an instruction, or a list with SLiCAPprotos.allResults objects. The data type of these instructions should be ‘poles’, ‘zeros’ or ‘pz’.
- xmin (int, float, str) – Minimum value of the x axis; defaults to None.
- xmax (int, float, str) – Maximum value of the x axis; defaults to None.
- ymin (int, float, str) – Minimum value of the y axis; defaults to None.
- ymax (int, float, str) – Maximum value of the y axis; defaults to None.
- xscale (str) – x axis scale factor; defaults to ‘’.
- yscale (str) – y axis scale factor; defaults to ‘’.
- show (bool) – If ‘True’ the plot will be shown in the workspace. Defaults to False.
Returns: fig
Return type:
-
plotSweep(fileName, title, results, sweepStart, sweepStop, sweepNum, sweepVar='auto', sweepScale='', xVar='auto', xScale='', xUnits='', axisType='auto', funcType='auto', yVar='auto', yScale='', yUnits='', noiseSources=None, show=False)¶ Plots a function by sweeping one variable and optionally stepping another.
The function to be plotted depends on the arguments ‘yVar’ and ‘funcType’:
- If funcType == ‘params’, the variable ‘yVar’ must be the name of a circuit parameter.
- If funcType == ‘auto’, the default function that will be plotted depends
on the data type of the instruction:
- data type == ‘noise’: funcType = ‘onoise’
- data type == ‘laplace’, ‘numer’ or ‘denom’: funcType = ‘mag’
- data type == ‘time’, ‘impulse’ or ‘step’: funcType = ‘time’
The variable plotted along the x-axis defaults to the sweep variable. However, for multivariate functions obtained with data type ‘params’, the x variable can be choosen from all circuit parameters.
- If sweepVar == ‘auto’, the sweep variable will be determined from the data type:
- data type == ‘noise’, ‘laplace’, ‘numer’ or ‘denom’: sweepVar = ini.frequency for data types ‘laplace’, ‘numer’ or ‘denom’ the laplace variable will be replaced with sympy.i*ini.frequency or with 2*sympy.pi*sympy.i*ini.frequency before sweeping, when ini.Hz == False, or ini.Hz== True, respectively.
- dataType == ‘time’, ‘impulse’ or ‘step’: sweepVar = sympy.Symbol(‘t’)
The type of axis can be ‘lin’, ‘log’, ‘semilogx’, ‘semilogy’ or ‘polar’.
Parameters: - fileName (str) – Name of the file for saving it to disk.
- title (str) – Title of the figure.
- results (list, SLiCAPprotos.allResults) – Results of the execution of an instruction, or a list with SLiCAPprotos.allResults objects.
- sweepStart (float, int, str) – Start value of the sweep parameter
- sweepStop (float, int, str) – Stop value of the sweep parameter
- sweepNum (int) – Number of points of the sweep parameter
- sweepVar (sympy.Symbol, str) – Name of the sweep variable
- sweepScale (str) – Scale factor of the sweep variable. Both the start and the stop value will be multiplied with a factor that corresponds with this scale factor.
- xVar – Name of the variable to be plotted along the x axis
- xScale (str) – Scale factor of the x axis variable.
- xUnits (str) – Units of the x axis variable.
- axisType (str) – Type of axis: ‘lin’, ‘log’, ‘semilogx’, ‘semilogy’ or ‘polar’.
- funcType (str) – Type of function can be: ‘mag’, ‘dBmag’, ‘phase’, ‘delay’, ‘time’, ‘onoise’, ‘inoise’ or ‘param’.
- yScale (str) – Scale factor of the y axis variable.
- yUnits (str) – Units of the y axis variable.
- noiseSources (list, str) – Noise sources of which the contribution to the detector- referred noise (funcType = ‘onoise’) or the source- referred noise (funcType = ‘inoise’) should be plotted. Can be ‘all’, a list with names of noise sources or an ID of a noise source.
- show (bool) – If ‘True’ the plot will be shown in the workspace.
Returns: fig
Return type:
-
stepParams(results, xVar, yVar, sVar, sweepList)¶ Returns parameter values as a result of sweeping and stepping parameters.
Called by SLiCAPplots.plotSweep() in cases in which funcType = ‘param’.
If parameter stepping is enabled it returns a tuple with two dictionaries:
- {stepVal[j]: [xVal[i] for i in range(len(sweepValues))], …}
- {stepVal[j]: [yVal[i] for i in range(len(sweepValues))], …}
If parameter stepping is disabled it returns a tuple with two lists:
- [xVal[i] for i in range(len(sweepValues))]
- [yVal[i] for i in range(len(sweepValues))]
Parameters: - results (SLiCAPprotos.allResults) – Results of the execution of an instruction with data type ‘params’.
- xVar – Name of the parameter to be plotted along the x axis
- yVar – Name of the parameter to be plotted along the y axis
- sVar – Name of the sweep parameter
- sweepList (list, numpy.array) – Array-like sweep values.
Returns: parameter values as a result of sweeping and stepping parameters.
Return type: tuple
-
class
trace(traceData)¶ Trace prototype.
Traces are plotted on axes, which are part of a figure.
Parameters: traceData (list) – list with list array-like X and Y data of the trace. Example: >>> x_data = np.linspace(0, 2*np.pi, 50) >>> y_data = np.sin(x_data) >>> sin_trace = trace([x_data, y_data])
-
color= None¶ Trace color (str) in matplotlib format. Defaults to False.
-
label= None¶ Trace label (str) that will be displayed in legend box. Defaults to ‘’.
-
lineType= None¶ Line type (str) in matplotlib format. Defaults to ‘-‘.
-
lineWidth= None¶ Line width (int) in pixels. Defaults to 2.
-
makeTable()¶ Returns a table with trace data in CSV format.
Returns: table: CSV table with column headings and x-data and y-data in columns Return type: str Example: >>> x_data = np.linspace(0, 2*np.pi, 10) >>> y_data = np.sin(x_data) >>> sin_trace = trace([x_data, y_data]) >>> sin_trace.yName = 'sin(x)' >>> print(sin_trace.makeTable()) x,sin(x) 0.000000000000e+00, 0.000000000000e+00 6.981317007977e-01, 6.427876096865e-01 1.396263401595e+00, 9.848077530122e-01 2.094395102393e+00, 8.660254037844e-01 2.792526803191e+00, 3.420201433257e-01 3.490658503989e+00, -3.420201433257e-01 4.188790204786e+00, -8.660254037844e-01 4.886921905584e+00, -9.848077530122e-01 5.585053606382e+00, -6.427876096865e-01 6.283185307180e+00, -2.449293598295e-16
-
marker= None¶ Marker type (str) in matplotlib format. Defaults to False.
-
markerColor= None¶ Marker color (str) in matplotlib format. Defaults to False.
-
markerFaceColor= None¶ Marker face color (str) in matplotlib format. Defaults to ‘none’.
-
markerSize= None¶ Marker size (int). Defaults to 7.
-
xData= None¶ Array-like data for the x-axis of the trace. On a polar axes this is the angle in radians.
-
xName= None¶ Heading (str) for the x column of a table. Defaults to ‘x’.
-
yData= None¶ Array-like data for the y-axis of the trace. On a polar axes this is the radius.
-
yName= None¶ Heading (str) for the y column of a table. Defaults to ‘y’.
-
-
traces2fig(traceDict, figObject, axis=[0, 0])¶ Adds traces generated from another application to an existing figure.
Parameters: - traceDict (dict) –
Dictionary with key-value pairs:
- key: str: label of the trace
- value: SLiCAPplots.trace trace object
- figObject (SLiCAPplots.figure) – figure object to which the traces must be added
- axis (list) – List with x position and y position of the axis to which the traces must be added. Defaults to [0, 0]
Returns: Updated figure object
Return type: - traceDict (dict) –