Create plots¶
SLiCAP provides some plot functions that facilitate easy plotting of graphs from execution results with automatic determination of colors, markers, plot legends, and axis labels.
Plot functions are collected in the SLiCAP module SLiCAPplots.py.
SLiCAP plots are hierarchically structured:
A figure object is the main object that can be plotted using its
.plot()
method.The figure’s
.axis
attribute is a list of lists with axis objects for one row, from left to right.The
.traces
attribute of each axis object is a list with trace objects that will be plotted the axis. Trace xdata, ydata, lables, colors, markers, etc, are all attributes of a trace object.
SLiCAP built-in figures are single-axis figures.
-
The function plotSweep() displays traces from expressions with one symbolic variable. It can be used for plotting time-domain responses, frequency-domain responses, and arbitrary single-variable functions.
Pole-zero and root-locus plots
The function plotPZ() displays X-Y scatter plots. These plots are configured for plotting the results of pole-zero analysis.
-
The function plot() generates X-Y line plots from a dictionary with traces. Such dictionaries can be generated from data from other applications, such as, LTspice, SImetrix, NGspice, or Cadence, or from
.csv
files (see Plot data from other applications).
Plots with a swept x-variable¶
Below a few examples using plotSweep().
>>> from SLiCAP import *
>>> prj = initProject('My first RC network') # Initialize a SLiCAP project
>>> instr = instruction() # Create an instance of an instruction object
>>> instr.setCircuit('myFirstRCnetwork.cir') # Create a circuit from 'myFirstRCnetwork.cir'
No errors found for circuit: 'My first RC network' from file: 'myFirstRCnetwork.cir'.
>>> instr.setSimType('numeric') # Define the simulation type
>>> instr.setSource('V1') # Define the signal source
>>> instr.setDetector('V_out') # Nodal voltage 'V_out' is detector voltage
>>> instr.setGainType('gain') # Define the gain type
>>> instr.setDataType('laplace') # Define the data type
>>> numGain = instr.execute() # Execute the instruction and assign the results to 'numGain'
>>> figMag = plotSweep('RCmag', 'Magnitude characteristic', numGain, 10, '100k', 100, yUnits = '-', show = True)
>>> figPol = plotSweep('RCpolar', 'Polar plot', numGain, 10, '100k', 100, axisType = 'polar', show = True)
>>> figdBmag = plotSweep('RCdBmag', 'dB magnitude characteristic', numGain, 10, '100k', 100, funcType = 'dBmag', show = True)
>>> figPhase = plotSweep('RCphase', 'Phase characteristic', numGain, 10, '100k', 100, funcType = 'phase', show = True)
>>> figDelay = plotSweep('RCdelay', 'Group delay characteristic', numGain, 10, '100k', 100, yScale = 'u', funcType = 'delay')
>>> i1.setDataType('step')
>>> numStep = i1.execute()
>>> figStep = plotSweep('RCstep', 'Unit step response', numStep, 0, 1, 50, sweepScale='m', show = True)
Stepping parameters¶
If a stepped-parameter instruction is executed, multiple traces will be plotted on the axis, one for each step value. The legend will show the step variable and the step variable and its value.
For array type stepping the legend text will be run: <i>
where the number i
indicates the i-th step using the i-th value for each step parameter.
Sweeping parameters¶
Cicuit parameters can be assigned a numeric value or a function of other parameters. In the case of a single-variable function it can be plotted with the plotSweep() function.
>>> from SLiCAP import *
>>> prj = initProject('My first RC network') # Initialize a SLiCAP project
>>> instr = instruction() # Create an instance of an instruction object
>>> instr.setCircuit('myFirstRCnetwork.cir') # Create a circuit from 'myFirstRCnetwork.cir'
No errors found for circuit: 'My first RC network' from file: 'myFirstRCnetwork.cir'.
Pole-zero and root-locus plots¶
>>> from SLiCAP import *
>>> prj = initProject('My first RC network') # Initialize a SLiCAP project
>>> instr = instruction() # Create an instance of an instruction object
>>> instr.setCircuit('myFirstRCnetwork.cir') # Create a circuit from 'myFirstRCnetwork.cir'
No errors found for circuit: 'My first RC network' from file: 'myFirstRCnetwork.cir'.
>>> instr.setSimType('numeric') # Define the simulation type
>>> instr.setSource('V1') # Define the signal source
>>> instr.setDetector('V_out') # Nodal voltage 'V_out' is detector voltage
>>> instr.setGainType('gain') # Define the gain type
>>> instr.setDataType('pz') # Define the data type
>>> pzGain = instr.execute() # Execute the instruction and assign the results to 'numGain'
>>> figPZ = plotPZ('PZ', 'Poles and zeros of the RC network', pzGain)
Stepping parameters and root locus plots¶
SLiCAP can plot the poles and zeros while stepping parameters. A root-locus plot in SLiCAP is essensially a stepped-parameter analysis with the data type set to ‘poles’. The formatting of the stepped pole-zero plots is as follows:
Data type ‘poles’ or ‘pz’
marker for each pole, first step: \(\times\)
marker for each pole, last step: \(+\)
marker for each pole, each step: \(\bullet\)
Data type ‘zeros’ or ‘pz’
marker for each zero, first step: \(\circ\)
marker for each zero, last step: \(\Box\)
marker for each zero, each step: \(\bullet\)
Paths of poles and/or zeros traced out by stepping parameters are displayed as a collection of dots: \(\bullet\). Only the first value and the last value of the step parameter is displayed in the legend. For array type stepping only run: 1 and run: <number of steps> is displayed in the legend.
X-Y plots¶
Plot data from other applications¶
Add traces to a figure¶
The function traces2fig() adds traces to a figure.