legend color does match with drawn lines?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Wan Ji
2021년 8월 20일
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;
채택된 답변
Bjorn Gustavsson
2021년 8월 20일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!