Main Content

Customize Linear Analysis Plots at Command Line

After you create a linear analysis response plot, you can programmatically edit the plot properties using a chart object. Programmatically editing response plot properties allows you to:

  • Efficiently customize a large number of plots in a batch analysis process.

  • Add response plots to a UI and update plot appearance based on user input.

You can also interactively modify individual response plot properties using the:

Chart Objects

To programmatically customize response plots, you must create the plot using one of the plotting functions in the following table. Each function returns a chart object whose properties you can modify using dot notation.

Plot Type

Plot Function

Chart Object Properties

Bode magnitude and phase

bodeplotBodePlot Properties

Hankel singular values

hsvplotHSVPlot Properties

Impulse response

impulseplotImpulsePlot Properties

Initial condition

initialplotInitialPlot Properties

Pole/zero maps for input/output pairs

iopzplotIOPZPlot Properties

Time response to arbitrary inputs

lsimplotLSimPlot Properties

Nichols chart

nicholsplotNicholsPlot Properties

Nyquist

nyquistplotNyquistPlot Properties

Pole/zero

pzplotPZPlot Properties

Root locus

rlocusplotRLocusPlot Properties

Singular values of the frequency response

sigmaplotSigmaPlot Properties

Step response

stepplotStepPlot Properties

For more information on specifying properties for a response plot, see the corresponding chart object properties. By modifying the chart object properties, you can customize plot features such as:

  • Titles and axis label text and font appearance

  • Axis limits and units

  • Response appearance, such as line color, style, and weight

  • Time or frequency vectors

  • Grid visibility and color

  • Input and output visibility for MIMO plots

  • Response characteristics to display, such as rise time or stability margins

You can also add responses to an existing plot using addResponse or modify the model associated with a response using dot notation.

Customize Linear Analysis Plot Appearance

Once you plot the response for a linear system, you can modify the plot appearance using dot notation. As an example, create a step plot for a transfer function model.

sys = tf(4,[1 0.5 4]);
sp = stepplot(sys);

MATLAB figure

To customize the plot appearance, modify the properties of chart object sp using dot notation. For example, change the line color and width for the response.

sp.Responses.Color = "black";
sp.Responses.LineWidth = 2;

MATLAB figure

You can also modify the units for a plot. By default, the step response uses the time units of the plotted linear system. For sys, the time unit is seconds. Change the units of the plot to minutes.

sp.TimeUnit = "minutes";

MATLAB figure

The x-axis label updates to reflect the change of unit. Changing the plot units does not change the time units of the underlying model. To change the model time units, do so before plotting the response.

You can also modify the plot title and axis labels for the plot. For example, change the title text, increase the size of the title font, and make the axes labels to bold.

sp.Title.String = "Step Plot";
sp.Title.FontSize = 16;
sp.XLabel.FontWeight = "bold";
sp.YLabel.FontWeight = "bold";

MATLAB figure

Depending on the plot type, you can configure and display response characteristics in the plot. For example, display the settling time on the step plot.

sp.Characteristics.SettlingTime.Visible = "on";

MATLAB figure

Modify or Add Linear Model Response

Once you create a response plot, you can modify the properties of the linear system and update the plot. Doing so helpful for examining the impact of varying model parameters or for updating response plots in a UI based on user input.

As an example, consider the Bode response for a state-space model.

sys = ss([-4.5 -6;0.6 0.7],[0;-1.5],[-1.1 0],-0.5);
bp = bodeplot(sys);

MATLAB figure

You can modify the linear system for the plot by changing the source data for the response. For example, remove the feedthrough component of the plotted state-space model by setting the D matrix to zero.

bp.Responses.SourceData.Model.D = 0;

MATLAB figure

You can also replace the model in a response plot with a new model object. For example, consider a second-order dynamic system with damping ratio zeta.

zeta = 0.5;
wn = 2;
sys2 = tf(wn^2,[1 2*zeta*wn wn^2]);

Plot the step response for this system.

sp = stepplot(sys2);

MATLAB figure

You can update the damping ratio of the model by creating a new transfer function model and replacing the model source data.

newZeta = 0.75;
sys3 = tf(wn^2,[1 2*newZeta*wn wn^2]);
sp.Responses.SourceData.Model = sys3;

MATLAB figure

You can also add a response to an existing plot using the addResponse function. For example, create a step response for sys2 and subsequently add the response for sys3.

sp2 = stepplot(sys2);
addResponse(sp2,sys3);
sp2.LegendVisible = "on";

MATLAB figure

If you have a plot with multiple responses, you can suppress the display of one or more plots without removing the corresponding response from the chart object. For example, hide the second response in the plot.

sp2.Responses(2).Visible = "off";

MATLAB figure

See Also

Related Topics