How can I assign different colors in my plot?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Voss
on 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 Comments
See Also
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!