MATLAB Answers

legend imformation is incorrect

4 views (last 30 days)
Please I am plotting the data attached with just the simple code below but the legends repeats the first color for the second plot.
plot(DownExtraction','m');
hold on
plot(Upperextraction','b');
xlabel('Wavelength');
ylabel('Intensity');
legend('Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
Please your help wil be appreciated.

Accepted Answer

Star Strider
Star Strider on 29 Sep 2019
You must be plotting something else that is not in the code you posted or the data you attached.
This code:
D1 = load('Upper extraction.mat');
UpperExtraction = D1.DS_DATA_ODU;
D2 = load('Down Extraction.mat');
DownExtraction = D2.DS_DATA_ODD;
plot(DownExtraction','m');
hold on
plot(UpperExtraction','b');
xlabel('Wavelength');
ylabel('Intensity');
legend('Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
produces this plot:
That appears correct to me.
Note that the line at zero intensity does not appear.
The problem may be that you are plotting something else afterwards, with the hold state still on.
Try this instead:
figure
plot(DownExtraction','m');
hold on
plot(UpperExtraction','b');
hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend('Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
Experiment to get the result you want.
  11 Comments
Star Strider
Star Strider on 8 Oct 2019
@Walter — Thank you!
@Yussif Moro Awelisah — Your data are confusing and not well documented.
This worked for me when I tried it (with the ‘Down.mat’ and ‘Upper.mat’ files attached to your latest Comment):
figure
hp1 = plot(Down','m');
hold on
hp2 = plot(Upper','b');
hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend([hp1(1),hp2(1)], 'Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
You need to experiment with the ‘hp’ handles (as I have called them here) to be sure they correspond with the data you are plotting. I have no idea what they are or how you calculated them, so I just experimented until I got them to work. If they are the reverse of what they should be, reverse the order of the ‘hp’ elements in the legend handle vector (between the square brackets []).
Note that ‘Down’ is a (6x500) double matrix, and ‘Upper’ is a (4x500) double matrix. You appear to be plotting the same data (or approximately the same data) several times.

Sign in to comment.

More Answers (1)

Yussif M. Awelisah
Yussif M. Awelisah on 8 Oct 2019
@Star Strider
@Walter Roberson
I am sincerely grateful. This worked for me and I am sincerely grateful for your loyalty and kindness.

Tags

Community Treasure Hunt

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

Start Hunting!