legend with specific colors

조회 수: 2 (최근 30일)
milad farshbaf
milad farshbaf 2019년 1월 6일
편집: milad farshbaf 2019년 1월 7일
hi, how can i use legend with my specific colors and Depth in this code?
figure
for n = 1:length(Lon)
if Depth(n,1)>=0 && Depth(n,1)<=20
jj = [0 1 0];
elseif Depth(n,1)>20 && Depth(n,1)<=40
jj = [0 1 1];
elseif Depth(n,1)>40 && Depth(n,1)<=60
jj = [0 1 0];
elseif Depth(n,1)>60 && Depth(n,1)<=90
jj = [1 0 0];
elseif Depth(n,1)>90 && Depth(n,1)<=10000
jj = [0 0 0];
end
h(n) = plot(Lon(n,1),Lat(n,1),'o','MarkerFaceColor',jj,'MarkerEdgeColor','k'); hold on
legend('0-20','20-40','40-60','60-90','90-10000');
end

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 1월 7일
Right now you are plotting one dataset of 'Lon' and 'Lat' at a time and this will give you a plot with number of datasets equal to the length of 'Lon' vector. You would like to plot all the datasets of 'Lon' and 'Lat' vectors with specific interval at once. So, you will have number of datasets according to the number of intervals you have. which will be easier to show on legend imo.
Here's one way to do it :
interval=[0,20,40,60,90,10000]; % Interval Matrix
col=hsv(length(interval)-1); % Color matrix for markers
figure
for n = 1:length(interval)-1
minI=interval(n); % max of Interval
maxI=interval(n+1); % min of Interval
Ind=find(Depth>=minI&Depth<maxI); % get indeces according to the interval
plot(Lon(Ind,1),Lat(Ind,1),'o','MarkerFaceColor',col(n,:),'MarkerEdgeColor','k');
hold on;
end
legend('0-20','20-40','40-60','60-90','90-10000');
I hope this helps.
  댓글 수: 1
milad farshbaf
milad farshbaf 2019년 1월 7일
편집: milad farshbaf 2019년 1월 7일
This is exactly what i want, tnx tnx :)))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by