%% Graph with Multiple x-Axes and y-Axes
% This example shows how to create a graph using the bottom and left
% sides of the axes for the first plot, and the top and
% right sides of the axes for the second plot.
%
%%
% Create the data to plot.

% Copyright 2015 The MathWorks, Inc.


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

%%
% Use the |line| function to plot |y1| versus |x1| using a red line. Set
% the color for the _x_-axis and _y_-axis to red. 
%
% *Note:* Starting in R2014b, you can use dot notation to set properties.
% If you are using an earlier release, use the
% <docid:matlab_ref.f67-432995> function instead, such as
% |set(ax1,'XColor','r')|.

figure
line(x1,y1,'Color','r')
ax1 = gca; % current axes
ax1.XColor = 'r';
ax1.YColor = 'r';

%%
% Create a second axes in the same location as the first axes by setting
% the position of the second axes equal to the position of the first axes.
% Specify the location of the _x_-axis as the top of the graph and the
% _y_-axis as the right side of the graph. Set the axes |Color| to |'none'|
% so that the first axes is visible underneath the second axes.

ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
    'XAxisLocation','top',...
    'YAxisLocation','right',...
    'Color','none');

%%
% Use the |line| function to plot |y2| versus |x2| on the second axes.
% Set the line color to black so that it matches the color of the
% corresponding _x_-axis and _y_-axis.
line(x2,y2,'Parent',ax2,'Color','k')

%%
% The graph contains two lines that correspond to different axes. The red line
% corresponds to the red axes. The black line corresponds to the black
% axes.
