How to specify the color of this contourf plot?

4 ビュー (過去 30 日間)
Leon
Leon 2021 年 9 月 3 日
コメント済み: Bjorn Gustavsson 2021 年 9 月 3 日
I'm trying to plot the landmask (logical 0 or 1) using a uniform color. Below is my code:
% Turning the landmask from logical to numerical.
M = NaN(landmask);
M(landmask) = 1;
[C1, h1] = m_contourf (X, Y, M, [1, 1]); %This is the contour I need help with.
hold on
% another contourf plot:
[C2, h2] = m_contourf (X, Y, Z2, [-5:1:45], 'LineStyle', 'none' );
caxis([0 45]);
How do I specify the color of the first contour to a uniform color of [0.7 0.7 0.7]?
I tried the below and it did not work.
[C1, h1] = m_contourf (X, Y, M, [1, 1], 'color', [0.7 0.7 0.7] );
Right now, its color is basically dictated by the "caxis([0 45])" command the same way as the 2nd contourf plot.
Thanks.

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 9 月 3 日
Maybe you can avoid the problem by using fill or patch by extracting the coordinates of the perimeters of the landmask?
Something like this:
[C1, h1] = m_contourf (X, Y, M, [1, 1]);
i1 = 1;
i2 = C1(2,i1);
idxPatch = 1;
while i1 < size(C1,2)
i2 = C1(2,i1);
i1 = i1+1;
hF(idxPatch) = fill(C1(1,i1:(i1+i2-1)),C1(2,i1:(i1+i2-1)),[0.7 0.7 0.7]);
hold on
idxPatch = idxPatch + 1; % yeah, yeah, dynamically growing hF but too much work to find out how many fields in landmask...
i1 = i2+i1;
end
Now you should've replaced the contour-patches with regular patches where you can controll the colour directly (in my matlab-version there's no obvious color or facecolor property of the h1).
HTH
  6 件のコメント
Leon
Leon 2021 年 9 月 3 日
Working now! Thank you so much.
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 9 月 3 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeExploration and Visualization についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by