フィルターのクリア

How to make one contour transparent in contourf?

51 ビュー (過去 30 日間)
Arnault
Arnault 2013 年 1 月 28 日
編集済み: Will Grant 2021 年 8 月 31 日
Hello, I have a contour plot with several layers define as follows:
[c,h]=contourf(X,Y,Z,[value1 value2 value3 value4]);
I would like to make a selected contour transparent, let's say the first contour defined by value1. Any thought on how to proceed? Thanks.
Arnault

採用された回答

José-Luis
José-Luis 2013 年 1 月 28 日
[C,h] = contourf(peaks(20),-4:1:4);
allH = allchild(h);
valueToHide = 1;
patchValues = cell2mat(get(allH,'UserData'));
patchesToHide = patchValues == valueToHide;
set(allH(patchesToHide),'FaceColor','k','FaceAlpha',0.8);
Note that you could set the FaceColor to white if that is what you mean by transparent. Otherwise you could set the FaceAlpha to zero for the patch to be transparent.
Please accept an answer if it helps you.
  3 件のコメント
Arnault
Arnault 2013 年 1 月 28 日
Thanks, works well!
Arnault
Arnault 2013 年 1 月 28 日
編集済み: Arnault 2013 年 1 月 28 日
I have a related question. The colorbar keeps the original color. Any idea on how I could do the same on the colorbar?

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

その他の回答 (2 件)

Will Grant
Will Grant 2021 年 8 月 31 日
編集済み: Will Grant 2021 年 8 月 31 日
See my answer here - working for R2020a

Leslie
Leslie 2015 年 2 月 3 日
This solution has stopped working in 2014b. Does anyone know if we still change the tranparency of 2D contour plots? If so how? Thanks
  1 件のコメント
Boris Belousov
Boris Belousov 2016 年 2 月 25 日
編集済み: Boris Belousov 2016 年 2 月 25 日
Unfortunately you have to manually define a contour of the area you want to make transparent. See how to make contour plots transparent.

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

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by