Contourf and colormap limits

610 ビュー (過去 30 日間)
Tomas Levy
Tomas Levy 2019 年 4 月 7 日
編集済み: Cris LaPierre 2023 年 5 月 17 日
Hi there!
Let's say I want to plot this:
contourf(peaks,16)
caxis([-2 2])
colorbar
Now I get:
But I want to show black contour lines only in the caxis limits AND also the color levels in the same limits, i.e. 16 color levels in [-2 2], not just 6 like in the picture.
Any ideas? Thanks

採用された回答

Cris LaPierre
Cris LaPierre 2019 年 4 月 8 日
編集済み: Cris LaPierre 2023 年 5 月 17 日
The problem is your data goes from [-6.5 8]. The 16 contour lines have been drawn for that. Then when you call caxis, you get rid of any color distinction above 2 or below -2 (>2 all have same color, <-2 all have same color). This does not affect where the actual contour lines go, though. Just the range of values used to assign colors.
Instead, specify (in increasing order) the values you want the contour lines at.
Compare the output of these 3 plots
p = peaks;
figure
contourf(p,16)
colorbar
figure
contourf(p,16)
caxis([-2 2])
colorbar
figure
contourf(p,linspace(-2,2,16))
colorbar
I think the last one does what you want.
  10 件のコメント
Megha Suswaram
Megha Suswaram 2021 年 2 月 19 日
Thank you! That worked super well for me!
Nabin
Nabin 2023 年 5 月 17 日
Thank you! Worked well for me too!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by