Scatter plot legend for only two of the three plotted categories
Mostra commenti meno recenti
I have a 1738x6 matrix ("stock2"), from which I plotted the 6th column (y-axis) and the 5th column (x-axis). I divided values from the 6th column to three categories; top 100 (red dots), bottom 100 (blue dots) and the rest (green dots). I have extracted these high and low values, they are called "high100" and "low100" in the code below.
I understand that I have only one y-value in the plot and that it contains the three different categories. But I can't find a way to create a legend for the plot so that it would show only red dots and blue dots from inside my y-value. All attempts either fail or show a green dot and the first label of the legend. Could someone kindly show how to create the desired legend? Everything else in the code runs nicely. And as an extra question: why is there a [ ] in the scatter plot when using a color map?
figure
% color map
c = zeros(size(stock2,1),3);
middle = stock2;
[~,j] = sort(stock2(:,6),'ascend');
remove = j([1:100 end-99:end],:);
middle(remove,:)=[];
% other points are green so blue and red can be easily distinguished
% blue didn't seem to stand out from the default black dots
d=length(middle);
for i=1:d
c(i,2)=1;
end
% red
a=length(middle)+1;
aa=a+99;
for i=a:aa
c(i,1)=1;
end
% blue
b=length(middle)+length(high100)+1;
bb=b+99;
for i=b:bb
c(i,3)=1;
end
scatter(stock2(:,5),[middle(:,6); stock2(high100,6); stock2(low100,6)],[],c,'.')
title('Stock2')
xlabel('Closing Price')
ylabel('Volume')
legend('100 highest volume days','100 lowest volume days')
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Legend in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
