plotyy

Plots two data sets against separate y-axes, left and right (older form of yyaxis).

Category: Graphics > Formatting and Annotation

Syntax

plotyy(x1, y1, x2, y2)

Plots y1 against the left y-axis and y2 against the right one.

[AX, H1, H2] = plotyy(___)

Also returns the two axes and the two line objects.

Description

Two quantities with very different ranges, such as a temperature and a pressure, are hard to read on one scale. plotyy overlays two axes in the same position: the left one carries the first data set and the right one the second, each with its own tick labels.

The function is kept for compatibility with older code. New programs should use yyaxis left and yyaxis right, which put both on a single axes object.

Input arguments

x1, y1
Data for the left axis.
x2, y2
Data for the right axis.

Output arguments

AX
Two-element array with the left and right axes.
H1, H2
Line objects of the first and second data sets.

Example

Two scales

x = 1:5;
[AX, H1, H2] = plotyy(x, x, x, 100*x.^2);
size(AX)
class(H1)
Output
ans = 1×2

     1     2
ans = 'matlab.graphics.chart.primitive.Line'

See also

yyaxis plot ylabel hold subplot