%% Specify Colors for Chart with Two y-Axes
% The yyaxis command creates an axes object with y-axes on the left and right sides. The left y-axis and corresponding plots use the first color in the axes color order. The right y-axis and corresponding plots use the second color in the axes color order. To change the colors, change the default value for the axes color order before plotting. Alternatively, you can specify the colors when plotting, and then set the y-axis to match.
%% Change Default Axes Color Order
% Specify the colors for a chart with two y-axes by changing the default axes color order.
% Create a new figure. Define two RGB color values, one for the left side and one for the right side. Change the default axes color order to these two colors. Set the default at the figure level so that the new colors affect only axes objects that are children of the figure fig and do not affect axes in other figures. Then, plot data.

fig = figure;
left_color = [.5 .5 0];
right_color = [0 .5 .5];
set(fig,'defaultAxesColorOrder',[left_color; right_color]);

y = [1 2 3; 4 5 6];
yyaxis left
plot(y)

z = [6 5 4; 3 2 1];
yyaxis right
plot(z)

%
%% Specify Colors When Plotting
% Specify the colors for a chart with two y-axes by setting the colors for each plot and then changing the color of each y-axis to match.
% Define two RGB color values, one for the left side and one for the right side. Create a chart with two y-axes. Plot three lines against the left side specifying their color using the Color name-value pair arugment. Then, set the YColor property of the axes object to the same color. Since the left side is active, the new YColor value affects the left y-axis.

left_color = [.5 .5 0];
right_color = [0 .5 .5];

y = [1 2 3; 4 5 6];
figure
yyaxis left
plot(y,'Color',left_color)
ax = gca;
ax.YColor = left_color;

%
% Use yyaxis right to activate the right side and plot three lines specifying their color using the Color name-value pair arugment. Then, set the YColor property of the axes object to the same color. Since the right side is active, the new YColor value affects the right y-axis.

z = [6 5 4; 3 2 1];
yyaxis right
plot(z,'Color',right_color)
ax.YColor = right_color;

% Copyright 2012 The MathWorks, Inc.