Legend Color and plot color mismatch
I have 8 sets of data I would like to plot and want every 2 to have the same color in the plot and in the legend. I would also like every 2 plots to have the same color for example I am trying to have plots 1 & 2 to have the same color plots 3 & 4 to have another color etc. For some reason when I plot the data the color on the plots themselves is fine but the legend color is wrong. The legend for plot A1 and A2 have default colors that I never set and the rest of legend colors are skewed by 1. For example I get B1 & B2 to be green instrad of yellow, I get C1 % C2 to be yellow instead of magenta etc. I have tried 2 methods for this one using the ‘legend_bonus’ and setting the legend that way and another method that is shown but commented out is when using the set for the plot make the displayname as shown either wayt i get the same result. Why is this happening and how to I fix this.
Thank you
legend_bonus = {‘A1 ‘, ‘A2 ‘,’B1 ‘, ‘B2 ‘,’C1 ‘, ‘C2 ‘,’D1 ‘, ‘D2 ‘}
%
h1 = plot(zplot_Ax1, zplot_Ay1,’o-‘,’Color’,’green’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘A1 ‘);
hold on
h1 = plot(zplot_Ax2, zplot_Ay2,’o-‘,’Color’,’green’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘A2 ‘);
hold on
%
h1 = plot(zplot_Bx1, zplot_By1,’o-‘,’Color’,’yellow’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘B1 ‘);
hold on
h1 = plot(zplot_Bx2, zplot_By2,’o-‘,’Color’,’yellow’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘B2 ‘);
hold on
%
h1 = plot(zplot_Cx1, zplot_Cy1,’o-‘,’Color’,’magenta’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘C1 ‘);
hold on
h1 = plot(zplot_Cx2, zplot_Cy2,’o-‘,’Color’,’magenta’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘C2 ‘);
hold on
%
h1 = plot(zplot_Dx1, zplot_Dy1,’o-‘,’Color’,’red’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘D1 ‘);
hold on
h1 = plot(zplot_Dx2, zplot_Dy2,’o-‘,’Color’,’red’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘D2 ‘);
hold on
title(‘title’);
xlabel(‘X axis’);
ylabel(‘Y axis’);
ax = gca;
ax.FontSize = 20;
legend(legend_bonus);
legend(‘Location’, ‘best’);I have 8 sets of data I would like to plot and want every 2 to have the same color in the plot and in the legend. I would also like every 2 plots to have the same color for example I am trying to have plots 1 & 2 to have the same color plots 3 & 4 to have another color etc. For some reason when I plot the data the color on the plots themselves is fine but the legend color is wrong. The legend for plot A1 and A2 have default colors that I never set and the rest of legend colors are skewed by 1. For example I get B1 & B2 to be green instrad of yellow, I get C1 % C2 to be yellow instead of magenta etc. I have tried 2 methods for this one using the ‘legend_bonus’ and setting the legend that way and another method that is shown but commented out is when using the set for the plot make the displayname as shown either wayt i get the same result. Why is this happening and how to I fix this.
Thank you
legend_bonus = {‘A1 ‘, ‘A2 ‘,’B1 ‘, ‘B2 ‘,’C1 ‘, ‘C2 ‘,’D1 ‘, ‘D2 ‘}
%
h1 = plot(zplot_Ax1, zplot_Ay1,’o-‘,’Color’,’green’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘A1 ‘);
hold on
h1 = plot(zplot_Ax2, zplot_Ay2,’o-‘,’Color’,’green’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘A2 ‘);
hold on
%
h1 = plot(zplot_Bx1, zplot_By1,’o-‘,’Color’,’yellow’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘B1 ‘);
hold on
h1 = plot(zplot_Bx2, zplot_By2,’o-‘,’Color’,’yellow’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘B2 ‘);
hold on
%
h1 = plot(zplot_Cx1, zplot_Cy1,’o-‘,’Color’,’magenta’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘C1 ‘);
hold on
h1 = plot(zplot_Cx2, zplot_Cy2,’o-‘,’Color’,’magenta’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘C2 ‘);
hold on
%
h1 = plot(zplot_Dx1, zplot_Dy1,’o-‘,’Color’,’red’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘D1 ‘);
hold on
h1 = plot(zplot_Dx2, zplot_Dy2,’o-‘,’Color’,’red’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘D2 ‘);
hold on
title(‘title’);
xlabel(‘X axis’);
ylabel(‘Y axis’);
ax = gca;
ax.FontSize = 20;
legend(legend_bonus);
legend(‘Location’, ‘best’); I have 8 sets of data I would like to plot and want every 2 to have the same color in the plot and in the legend. I would also like every 2 plots to have the same color for example I am trying to have plots 1 & 2 to have the same color plots 3 & 4 to have another color etc. For some reason when I plot the data the color on the plots themselves is fine but the legend color is wrong. The legend for plot A1 and A2 have default colors that I never set and the rest of legend colors are skewed by 1. For example I get B1 & B2 to be green instrad of yellow, I get C1 % C2 to be yellow instead of magenta etc. I have tried 2 methods for this one using the ‘legend_bonus’ and setting the legend that way and another method that is shown but commented out is when using the set for the plot make the displayname as shown either wayt i get the same result. Why is this happening and how to I fix this.
Thank you
legend_bonus = {‘A1 ‘, ‘A2 ‘,’B1 ‘, ‘B2 ‘,’C1 ‘, ‘C2 ‘,’D1 ‘, ‘D2 ‘}
%
h1 = plot(zplot_Ax1, zplot_Ay1,’o-‘,’Color’,’green’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘A1 ‘);
hold on
h1 = plot(zplot_Ax2, zplot_Ay2,’o-‘,’Color’,’green’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘A2 ‘);
hold on
%
h1 = plot(zplot_Bx1, zplot_By1,’o-‘,’Color’,’yellow’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘B1 ‘);
hold on
h1 = plot(zplot_Bx2, zplot_By2,’o-‘,’Color’,’yellow’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘B2 ‘);
hold on
%
h1 = plot(zplot_Cx1, zplot_Cy1,’o-‘,’Color’,’magenta’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘C1 ‘);
hold on
h1 = plot(zplot_Cx2, zplot_Cy2,’o-‘,’Color’,’magenta’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘C2 ‘);
hold on
%
h1 = plot(zplot_Dx1, zplot_Dy1,’o-‘,’Color’,’red’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘D1 ‘);
hold on
h1 = plot(zplot_Dx2, zplot_Dy2,’o-‘,’Color’,’red’);
set( h1, ‘LineWidth’, 4)%, ‘DisplayName’, ‘D2 ‘);
hold on
title(‘title’);
xlabel(‘X axis’);
ylabel(‘Y axis’);
ax = gca;
ax.FontSize = 20;
legend(legend_bonus);
legend(‘Location’, ‘best’); legend color MATLAB Answers — New Questions