How can I assign different colors in my plot?

2 ビュー (過去 30 日間)
Lareeb Moeen
Lareeb Moeen 2022 年 2 月 18 日
回答済み: Voss 2022 年 2 月 18 日
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?

回答 (1 件)

Voss
Voss 2022 年 2 月 18 日
% 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

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by