addaxis
Plots the given dataset on a new vertical axis in an existing 2D plot.
Syntax
[ax, h] = addaxis(y)
[ax, h] = addaxis(x, y)
[ax, h] = addaxis(x, y, x, y, ...)
[ax, h] = addaxis(x, y, fmt)
[ax, h] = addaxis(..., property, value, ...)
[ax, h] = addaxis(hAxes, ...)
Inputs
- x, y
- Range of the x and y axes.
- fmt
- Formatting string for the curve. It can be any combination of the following strings:
- line style: '-', '-.', ':', '--', '-:'.
- line color: 'r', 'g', 'b', 'c', 'y', 'm', 'w', 'k'.
- marker style: 's', 'o', 'd', 'x', 'v', '^', '+', '*', '.'.
- property
- Properties that control the appearance or behavior of the graphics object.
- value
- Value of the properties.
- hAxes
- Axis handle.
Outputs
- ax
- A vector that contains the handle of the Axes object and the handle of the new Y-Axis object.
- h
- Handle(s) of the line graphics object.
Examples
clf;
[ax, h] = addaxis(0:0.1:5, cos(0:0.1:5));
clf;
x = 0:0.1:5;
plot(x, cos(x));
[ax, h] = addaxis(x, sin(x));
clf;
x = 0:0.1:5;
plot(x, cos(x));
[ax1, h1] = addaxis(x, sin(x));
[ax2, h2] = addaxis(x, sin(x+2), ':s');
legend;
clf;
x = 0:0.1:5;
plot(x, cos(x));
[ax1, h1] = addaxis(x, sin(x));
[ax2, h2] = addaxis(x, sin(x+2), ':s');
set(ax2(2), {'fontsize', 'ynumericformat', 'ynumericprecision'}, {10, 'fixed', 2});
ylabel('Y axis');
ylabel(ax1(2), 'Y1 axis');
ylabel(ax2(2), 'Y2 axis');
legend;
clf;
x = 0:0.1:5;
h = plot(x, [cos(x); 2*cos(x)]);
[ax, h1] = addaxis(x, sin(x));
set(h(2),'yaxis', ax(2));
ylim([-1.5 1.5]);
ylim(ax(2), [-2 2]);
legend;
Comments
addaxis is available only in 2D X-Y plots.
New vertical axes are positioned on the right side of the plot.
The new vertical axes objects are children of the Axes object. The 'secondaryyaxis' property of the Axes object refers to the first vertical axis on the right side of the plot.
The vertical axis color is the same as the color of the first curve plotted on it.
It is possible to delete a vertical axis and the curves plotted on it using the delete command.