Functions to load and plot data from multiple simulation and linearization files at once
Plot multiple linearizations onto a single Bode diagram.
Arguments:
lins: Linearization result or list of results (instances of linres.LinRes)
axes: Tuple (pair) of axes for the magnitude and phase plots
If axes is not provided, then axes will be created in a new figure.
pair: Tuple of (input index, output index) for the transfer function to be chosen from each system (applied to all)
This is ignored if the system is SISO.
label: Label for the figure (ignored if axes is provided)
This will be used as the base filename if the figure is saved.
title: Title for the figure
labels: Label or list of labels for the legends
If labels is None, then no label will be used. If it is an empty string (‘’), then the base filenames will be used.
colors: Color or list of colors that will be used sequentially
Each may be a character, grayscale, or rgb value.
styles: Line/dash style or list of line/dash styles that will be used sequentially
Each style is a string representing a linestyle (e.g., “–”) or a tuple of on/off lengths representing dashes. Use “” for no line and “-” for a solid line.
leg_kwargs: Dictionary of keyword arguments for matplotlib.pyplot.legend()
If leg_kwargs is None, then no legend will be shown.
**kwargs: Additional arguments for control.freqplot.bode()
Returns:
Example:
>>> import os
>>> from glob import glob
>>> from modelicares import LinRes, multibode, saveall, read_params
>>> from numpy import pi, logspace
>>> lins = map(LinRes, glob('examples/PID/*/*.mat'))
>>> labels = ["Ti=%g" % read_params('Ti', os.path.join(lin.dir, 'dsin.txt'))
... for lin in lins]
>>> multibode(lins,
... title="Bode Plot of Modelica.Blocks.Continuous.PID",
... label='examples/PIDs-bode', omega=2*pi*logspace(-2, 3),
... labels=labels, leg_kwargs=dict(loc='lower right'))
(<matplotlib.axes._subplots.AxesSubplot object at 0x...>, <matplotlib.axes._subplots.AxesSubplot object at 0x...>)
>>> saveall()
Saved examples/PIDs-bode.pdf
Saved examples/PIDs-bode.png
Load multiple Modelica simulation and/or linearization results.
Arguments:
locations: Input filename, directory, or list of these
Wildcards (‘*’) may be used in the path(s).
Returns:
Either may be an empty list.
Example:
>>> from modelicares import *
# By file:
>>> multiload(['examples/ChuaCircuit.mat', 'examples/PID/*/*.mat'])
Valid: SimRes('.../examples/ChuaCircuit.mat')
Valid: LinRes('.../examples/PID/1/dslin.mat')
Valid: LinRes('.../examples/PID/2/dslin.mat')
([SimRes('.../examples/ChuaCircuit.mat')], [LinRes('.../examples/PID/1/dslin.mat'), LinRes('.../examples/PID/2/dslin.mat')])
# By directory:
>>> multiload('examples')
Valid: SimRes('...ChuaCircuit.mat')
Valid: LinRes('...PID.mat')...
Valid: SimRes('...ThreeTanks.mat')
([SimRes('...ChuaCircuit.mat'), SimRes('...ThreeTanks.mat')], [LinRes('...PID.mat')])
Plot multiple linearizations onto a single Nyquist diagram.
Arguments:
lins: Linearization result or list of results (instances of linres.LinRes)
ax: Axes onto which the Nyquist diagrams should be plotted
If ax is not provided, then axes will be created in a new figure.
pair: Tuple of (input index, output index) for the transfer function to be chosen from each system (applied to all)
This is ignored if the system is SISO.
label: Label for the figure (ignored if axes is provided)
This will be used as the base filename if the figure is saved.
title: Title for the figure
- xlabel: x-axis label
- ylabel: y-axis label
labels: Label or list of labels for the legends
If labels is None, then no label will be used. If it is an empty string (‘’), then the base filenames will be used.
colors: Color or list of colors that will be used sequentially
Each may be a character, grayscale, or rgb value.
leg_kwargs: Dictionary of keyword arguments for matplotlib.pyplot.legend()
If leg_kwargs is None, then no legend will be shown.
**kwargs: Additional arguments for control.freqplot.nyquist()
If textFreq is not specified, then only the frequency points of the first system will have text labels.
Returns:
- ax: Axes of the Nyquist plot
Example:
>>> import os
>>> from glob import glob
>>> from modelicares import LinRes, multinyquist, saveall, read_params
>>> from numpy import pi, logspace
>>> lins = map(LinRes, glob('examples/PID/*/*.mat'))
>>> labels = ["Td=%g" % read_params('Td', os.path.join(lin.dir, 'dsin.txt'))
... for lin in lins]
>>> multinyquist(lins,
... title="Nyquist Plot of Modelica.Blocks.Continuous.PID",
... label='examples/PIDs-nyquist', textFreq=True,
... omega=2*pi*logspace(-1, 3, 81), labelFreq=20,
... labels=labels)
<matplotlib.axes._subplots.AxesSubplot object at 0x...>
>>> saveall()
Saved examples/PIDs-nyquist.pdf
Saved examples/PIDs-nyquist.png
Plot data from multiple simulations in 2D Cartesian coordinates.
This method simply calls simres.SimRes.plot() from multiple instances of simres.SimRes.
A new figure is created if necessary.
Arguments:
sims: Simulation result or list of results (instances of simres.SimRes)
suffixes: Suffix or list of suffixes for the legends (see simres.SimRes.plot())
If suffixes is None, then no suffix will be used. If it is an empty string (‘’), then the base filenames will be used.
color: Single entry, list, or itertools.cycle of colors that will be used sequentially
Each entry may be a character, grayscale, or rgb value.
dashes: Single entry, list, or itertools.cycle of dash styles that will be used sequentially
Each style is a tuple of on/off lengths representing dashes. Use (0, 1) for no line and (None ,None) for a solid line.
**kwargs: Propagated to simres.SimRes.plot() (and thus to base.plot() and finally matplotlib.pyplot.plot())
Returns:
Example:
>>> from glob import glob
>>> from modelicares import SimRes, multiplot, saveall
>>> sims = map(SimRes, glob('examples/ChuaCircuit/*/*.mat'))
>>> multiplot(sims, title="Chua Circuit", label='examples/ChuaCircuits',
... suffixes=['L.L = %.0f H' % sim.get_IV('L.L')
... for sim in sims], # Read legend parameters.
... ynames1='L.i', ylabel1="Current")
(<matplotlib.axes._subplots.AxesSubplot object at 0x...>, None)
>>> saveall()
Saved examples/ChuaCircuits.pdf
Saved examples/ChuaCircuits.png