legend color does match with drawn lines?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
SANDEEP SINGH RANA
il 20 Ago 2021
Risposto: Bjorn Gustavsson
il 20 Ago 2021
Hi,
I draw the plot and run the code but the legends color does not match with the line drawn? Does not Why, previously when i run the same code, it's showing perfectly fine but this time it's don't.
Can I changes the color code now or I have to run the codes again as it will take 12 hours to run the same code. The code i written for the plot are as follows:
fig3 = figure(3);
saveas(fig3,'BER.png');
semilogy(t,ber_fixed(1,:),'-ok','linewidth',2); hold on; grid on;
semilogy(t,ber_dynamic(1,:),'--ok','linewidth',2);
semilogy(t,ber_fixed1(2,:),'-o','linewidth',2); hold on;
semilogy(t,ber_dynamic1(2,:),'-+r','linewidth',2);
legend('Fixed user-1','Dynamic user-1','Fixed1 user-2','Dynamic1 user-2');
xlabel('No. of simulated positions(t_m)');
ylabel('Individual bit error rate (BER)');
axis([1 position 0 1]);
Please help me to resolve the issue, because donot know run same code will or will not show same mistake again.
1 Commento
Wan Ji
il 20 Ago 2021
It's becuase you hold all the lines in the figure at the first run of your code, and later you run the code again, the two different colors may mix together to produce another color. What you need to do is just use clf right after the command figure.
fig3 = figure(3);
clf;
Risposta accettata
Bjorn Gustavsson
il 20 Ago 2021
When you want proper control of what is shown in legends always use the graphics-handles returned by the plotting-functions:
fig3 = figure(3);
saveas(fig3,'BER.png');
ph = semilogy(t,ber_fixed(1,:),'-ok','linewidth',2); hold on; grid on;
ph(2) = semilogy(t,ber_dynamic(1,:),'--ok','linewidth',2);
ph(3) = semilogy(t,ber_fixed1(2,:),'-o','linewidth',2); hold on;
ph(4) = semilogy(t,ber_dynamic1(2,:),'-+r','linewidth',2);
legend(ph,'Fixed user-1','Dynamic user-1','Fixed1 user-2','Dynamic1 user-2');
xlabel('No. of simulated positions(t_m)');
ylabel('Individual bit error rate (BER)');
axis([1 position 0 1]);
Here you can exclude some lines from the legend by simply selecting a subset of ph in the legend-call, and manipulate the line style, color and width etc after the initial plotting to "spice-up" the plot as you see fit.
HTH
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!