yyaxis

Selects the left or right y-axis so one plot can use two different y scales.

Category: Graphics > Formatting and Annotation

Syntax

yyaxis left

Makes the left y-axis active. The first call also creates the pair of axes.

yyaxis right

Makes the right y-axis active. Later plot calls draw against it.

yyaxis(ax, side)

Applies the choice to the axes object ax instead of the current axes.

Description

Each side of a two-sided plot has its own limits, ticks and label, and each keeps its own set of lines. After yyaxis left, commands such as plot, ylabel and ylim act on the left scale; after yyaxis right they act on the right one.

This is the usual way to compare quantities with very different magnitudes over the same x range, for example a quadratic and an exponential.

Input arguments

side
'left' or 'right'.
ax
Optional axes handle.

Example

Two y scales

x = 0:0.5:2;
yyaxis left
plot(x, x.^2)
ylabel('square')
yyaxis right
plot(x, exp(x))
ylabel('exponential')
ax = gca;
disp(ax.YAxisLocation)
Output
right

See also

plot ylabel ylim gca hold