Legend not matching the data

11 views (last 30 days)
I have weird data and not enough time to figure out the for loop stuff, so I did a basic plotting thing. But the legend is not matching my data. Is it the size of the legend or something?
j1 = plot(temp2412,original2412(:,1),'-o','Color',C6,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C6,'MarkerFaceColor',C6);
hold on
j2 = plot(temp2412,original2412(:,2),'-o','Color',C1,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C1,'MarkerFaceColor',C1);
j3 = plot(temp2412,original2412(:,3),'-o','Color',C3,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C3,'MarkerFaceColor',C3);
j4 = plot(temp3624,original3624(:,1),'-o','Color',C8,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C8,'MarkerFaceColor',C8);
j5 = plot(temp3018,original3018(:,1),'-o','Color',C10,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C10,'MarkerFaceColor',C10);
j6 = plot(temp2412,aged2412(:,1),'--o','Color',C6,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C6,'MarkerFaceColor',C6);
j7 = plot(temp2412,aged2412(:,2),'--o','Color',C1,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C1,'MarkerFaceColor',C1);
j8 = plot(temp2412,aged2412(:,3),'--o','Color',C3,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C3,'MarkerFaceColor',C3);
j9 = plot(temp3624,aged3624(:,1),'--o','Color',C8,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C8,'MarkerFaceColor',C8);
j10 = plot(temp3624,aged3624(:,2),'--o','Color',C10,'LineWidth',lw,'MarkerSize',ms,'MarkerEdgeColor',C10,'MarkerFaceColor',C10);
leg = [j1,j2,j3,j4,j5,j6,j7,j8,j9,j10];
xlim([-40 -6])
ylim([0 700]);
xlabel('Temperature (°C)','FontSize',fontsize);
ylabel('Stiffness (MPa)','FontSize',fontsize);
set(gca,'fontsize',22);
grid on
ax = gca;
legend(leg,'PEN 70/100 O','S-E1 O','S-E2 O','S-R1 O','S-R2 O','PEN 70/100 A','S-E1 A','S-E2 A','S-R1 A','S-R2 A');

Accepted Answer

Star Strider
Star Strider on 18 Oct 2021
It is possible to label the individual plots in the plot calls.
.
  2 Comments
Herline van der Spuy
Herline van der Spuy on 18 Oct 2021
I tried that, at first I thought it did not work. But then I changed one marker's symbol to a triangle. It does show the dashed line, the marker is just blocking it. So my new question would be: How to I increase the size of the legend thingy so as to show the dashed line.
Star Strider
Star Strider on 18 Oct 2021
That would probably require adjusting the Position property of the legend object.
Example —
x = 1:10;
y = rand(3,10);
figure
plot(x, y)
legend('Row 1','Row 2','Row 3', 'Location','NE')
figure
plot(x, y)
hleg = legend('Row 1','Row 2','Row 3', 'Location','NE');
lgdpos = hleg.Position;
hleg.Position = lgdpos+[-0.3 -0.25 0.3 0.25];
hleg.FontSize = 12;
Experiment with the other properties (if necessary) to get the desired result.
.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!