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 Center および File ExchangeLegend についてさらに検索

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by