Azzera filtri
Azzera filtri

Why are the colours in the legend different?

4 visualizzazioni (ultimi 30 giorni)
Em
Em il 28 Ago 2022
Risposto: Cris LaPierre il 28 Ago 2022
Can anyone see why my legend might not be appearing correctly?
plot(powerpc,SR09depth100mms,'-o','color',[1 .78 .1],'LineWidth',1)
xlabel('Power/mW')
ylabel('Trench Depth/\mum')
title('100mms^-^1 scan rate tracks')
hold on
plot(powerpc,SR08depth100mms,'-o','color',c(25,:),'LineWidth',1)
hold on
plot(powerpc,SR07depth100mms,'-o','color',c(45,:),'LineWidth',1)
hold on
plot(powerpc,SR06depth100mms,'-o','color',c(65,:),'LineWidth',1)
hold on
plot(powerpc,SR05depth100mms,'-o','color',c(75,:),'LineWidth',1)
hold on
plot(powerpc,SR04depth100mms,'-o','color',c(85,:),'LineWidth',1)
hold on
%plot(powerpc,SR03depth100mms,'-o','color',[.1 .4 .1],'LineWidth',1)
%plot(powerpc,SR03depth100mms,'-o','color','magenta','LineWidth',1)
plot(powerpc,SR03depth100mms,'-o','color',[.7 .4 .5],'LineWidth',1)
hold on
plot(powerpc,SR02depth100mms,'-o','color','k','LineWidth',1)
%legend({'DC=0.9@100mm/s','DC=0.8@100mm/s','DC=0.7@100mm/s','DC=0.6@100mm/s','DC=0.5@100mm/s','DC=0.4@100mm/s','DC=0.3@100mm/s','DC=0.2@100mm/s'},'Location','northwest','Orientation','vertical')
ylim([0 6])
legend({'DC=0.9','DC=0.8','DC=0.7','DC=0.6','DC=0.5','DC=0.4','DC=0.3','DC=0.2'},'Location','northwest','Orientation','vertical')
  3 Commenti
Walter Roberson
Walter Roberson il 28 Ago 2022
We do not know what color values are in those rows of c ?
I do not see any mismatch between the colors of the lines and the colors that appear in the legend ?
Please be more specific in pointing out what you see as being a problem.
Also, I suggest that you consider using the 'DisplayName' option on the plot calls, and then your legend() call would just be to establish the position and orientation. That would save having to edit the legend call each time you add or remove a plot line.
dpb
dpb il 28 Ago 2022
Well, we don't have any data so no idea what the colormap(?) variable c is nor the data itself to try to compare to, so very little (as in not a thing) we can say specifically other than you have eight (8) calls to plot() but only seven(7) lines are visible -- that could be one is off scale entirely or NaN so isn't rendered or...
The legend lines that do show appear to match the colors as would expect; what do you think isn't as expected?

Accedi per commentare.

Risposte (1)

Cris LaPierre
Cris LaPierre il 28 Ago 2022
Legend is consistent with your code. Why do you think it is wrong?
Here's an attempt at recreating your plot. Note that I elected to make the values for 0.4 NaN. They could also be the same values as 0.9.
powerpc = [27 42 56 70];
SR09depth100mms = [1.3 4 4.1 4.8];
SR08depth100mms = [1.6 1.9 3.7 3.8];
SR07depth100mms = [0.9 1.5 2.1 3];
SR06depth100mms = [0.8 1.95 1.75 3.2];
SR05depth100mms = [0.3 1 1.2 1.8];
SR04depth100mms = [nan nan nan nan];
SR03depth100mms = [0.4 1.3 2.3 1.95];
SR02depth100mms = [0 0 0.1 0.5];
c = parula(100);
plot(powerpc,SR09depth100mms,'-o','color',[1 .78 .1],'LineWidth',1)
xlabel('Power/mW')
ylabel('Trench Depth/\mum')
title('100mms^-^1 scan rate tracks')
hold on
plot(powerpc,SR08depth100mms,'-o','color',c(25,:),'LineWidth',1)
hold on
plot(powerpc,SR07depth100mms,'-o','color',c(45,:),'LineWidth',1)
hold on
plot(powerpc,SR06depth100mms,'-o','color',c(65,:),'LineWidth',1)
hold on
plot(powerpc,SR05depth100mms,'-o','color',c(75,:),'LineWidth',1)
hold on
plot(powerpc,SR04depth100mms,'-o','color',c(85,:),'LineWidth',1)
hold on
%plot(powerpc,SR03depth100mms,'-o','color',[.1 .4 .1],'LineWidth',1)
%plot(powerpc,SR03depth100mms,'-o','color','magenta','LineWidth',1)
plot(powerpc,SR03depth100mms,'-o','color',[.7 .4 .5],'LineWidth',1)
hold on
plot(powerpc,SR02depth100mms,'-o','color','k','LineWidth',1)
%legend({'DC=0.9@100mm/s','DC=0.8@100mm/s','DC=0.7@100mm/s','DC=0.6@100mm/s','DC=0.5@100mm/s','DC=0.4@100mm/s','DC=0.3@100mm/s','DC=0.2@100mm/s'},'Location','northwest','Orientation','vertical')
ylim([0 6])
legend({'DC=0.9','DC=0.8','DC=0.7','DC=0.6','DC=0.5','DC=0.4','DC=0.3','DC=0.2'},'Location','northwest','Orientation','vertical')
hold off % Added this so the plot is repeatable run to trun

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by