Graphics |
Plotting with Two Y-Axes
The plotyy
command enables you to create plots of two data sets and use both left and right side y-axes. You can also apply different plotting functions to each data set. For example, you can combine a line plot with a stem plot of the same data.
Combining Linear and Logarithmic Axes
You can use plotyy
to apply linear and logarithmic scaling to compare two data sets having a different range of values.
t = 0:900; A = 1000; a = 0.005; b = 0.005; z1 = A*exp(-a*t); z2 = sin(b*t); [haxes,hline1,hline2] = plotyy(t,z1,t,z2,'semilogy','plot');
This example saves the handles of the lines and axes created to adjust and label the graph. First, label the axes whose y value ranges from 10 to 1000. This is the first handle in haxes
because we specified this plot first in the call to plotyy
. Use the axes
command to make haxes(1)
the current axes, which is then the target for the ylabel
command.
Now make the second axes current and call ylabel
again.
You can modify the characteristics of the plotted lines in a similar way. For example, to change the line style of the second line plotted to a dashed line, use the statement
See "Using Multiple X and Y Axes" in the "Axes Properties" chapter for an example that employs double x- and y-axes.
See LineSpec
for additional line properties.
Plotting Imaginary and Complex Data | Setting Axis Parameters |