legend with specific colors
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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.
추가 답변 (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!