How can I assign different colors in my plot?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I need to assign each layer a different color, but I need to do it using the commands on the figure window. Any way to do it?

0 Commenti
Risposte (1)
Voss
il 18 Feb 2022
% some random GR data:
depth = linspace(3150,3400,500).';
GR = 20*randn(500,1)+120;
% and some layer boundaries:
tops = [3200 3270 3340].';
% plot the layer boundaries:
plot([0 240],[tops tops],'--k');
hold on
set(gca(),'XLim',[0 240],'YDir','reverse');
% Now plot one new line per layer, each with a different color:
N = numel(tops)+1;
colors = get(gca(),'ColorOrder');
colors = colors(mod(0:N-1,size(colors,1))+1,:);
tops_temp = [-Inf; tops; Inf];
for ii = 1:N
% idx here is a logical index saying whether each sample depth is
% within the current layer:
idx = depth >= tops_temp(ii) & depth < tops_temp(ii+1);
% use idx to plot only those GR samples and associated depths within
% the layer:
plot(GR(idx),depth(idx),'Color',colors(ii,:));
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Color and Styling in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
