%% Display Data with Multiple x-Axes and y-Axes
% Since R2019b
% To plot two sets of data with separate x- and y-axes, create two separate axes objects in a tiled chart layout. Within one of the axes objects, move the x-axis to the top of the plot box, and move the y-axis to the right side of the plot box.
% For example, you can create two plots that have different x- and y-axis limits.
% First, create two sets of x- and y-coordinates.

x1 = 0:0.1:40;
y1 = 4.*cos(x1)./(x1+2);
x2 = 1:0.2:20;
y2 = x2.^2./x2.^3;

%
% Create a tiled chart layout and an axes object. Then plot into the axes:
% Create a 1-by-1 tiled chart layout t.
% Create an axes object ax1 by calling the axes function and specifying t as the parent object.
% Plot x1 and y1 as a red line, and specify ax1 as the target axes.
% Change the color of the x-axis and y-axis to match the plotted line. Setting properties on the axes after plotting ensures that the settings persist.

t = tiledlayout(1,1);
ax1 = axes(t);
plot(ax1,x1,y1,'-r')
ax1.XColor = 'r';
ax1.YColor = 'r';

%
% Create a second axes object and plot the second set of data in black rather than red. Then, set properties on the second axes object to move the x-axis and y-axis, and to ensure that neither plot obscures the other.
% Create an axes object ax2 by calling the axes function and specifying t as the parent object.
% Plot x2 and y2 as a black line, and specify ax2 as the target axes.
% Move the x-axis to the top, and move the y-axis to the right.
% Set the color of the axes object to 'none' so that the underlying plot is visible.
% Turn off the plot boxes to prevent the box edges from obscuring the x- and y-axes.

ax2 = axes(t);
plot(ax2,x2,y2,'-k')
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
ax1.Box = 'off';
ax2.Box = 'off';

% Copyright 2020 The MathWorks, Inc.