legend with specific colors
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
milad farshbaf
el 6 de En. de 2019
Editada: milad farshbaf
el 7 de En. de 2019
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 comentarios
Respuesta aceptada
Shubham Gupta
el 7 de En. de 2019
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 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!