Inconsistancy of colorbars across contourf() plots
1 回表示 (過去 30 日間)
古いコメントを表示
I am comparing pressure contours across several test cases, so I need for the levels, and the colors coresponding to each level to be consistant. Here is an example:
p1 = contourf(X, Y, Z,-3:0.5:1, "LineWidth", 0.2);
cb1 = colorbar("Direction","reverse");
ylim(cb1, [-3 1])
p2 = contourf(X, Y, Z,-3:0.5:1, "LineWidth", 0.2);
cb2 = colorbar("Direction","reverse");
ylim(cb2, [-3 1])
p3 = contourf(X, Y, Z, -3:0.5:1, "LineWidth", 0.2);
cb3 = colorbar("Direction","reverse");
ylim(cb3, [-3 1])
So I am not posting the complete code, but want to show how I am declairing the same levels for each contourf() and the same bounds for each colorbar. Here is an example of the figures I am generating:
So the levels are consistant, and the limits of the colorbar are consistant, but the mapping of color to value changes with each plot. How can I specify this correctly?
Thanks
0 件のコメント
採用された回答
Voss
2023 年 12 月 3 日
Use clim() instead of setting the y-limits of the colorbars.
X = 1:10;
Y = 1:10;
Z1 = 4*rand(10)-3;
Z2 = 2*rand(10)-3;
Z3 = 2*rand(10)-1;
figure('Position',[10 10 1000 400])
tl = tiledlayout(1,3);
title(tl,'clim(_)','Interpreter','none');
nexttile
p1 = contourf(X, Y, Z1,-3:0.5:1, "LineWidth", 0.2);
cb1 = colorbar("Direction","reverse");
clim([-3 1])
nexttile
p2 = contourf(X, Y, Z2,-3:0.5:1, "LineWidth", 0.2);
cb2 = colorbar("Direction","reverse");
clim([-3 1])
nexttile
p3 = contourf(X, Y, Z3, -3:0.5:1, "LineWidth", 0.2);
cb3 = colorbar("Direction","reverse");
clim([-3 1])
figure('Position',[10 10 1000 400])
tl = tiledlayout(1,3);
title(tl,'ylim(cb,_)','Interpreter','none');
nexttile
p1 = contourf(X, Y, Z1,-3:0.5:1, "LineWidth", 0.2);
cb1 = colorbar("Direction","reverse");
ylim(cb1, [-3 1])
nexttile
p2 = contourf(X, Y, Z2,-3:0.5:1, "LineWidth", 0.2);
cb2 = colorbar("Direction","reverse");
ylim(cb2, [-3 1])
nexttile
p3 = contourf(X, Y, Z3, -3:0.5:1, "LineWidth", 0.2);
cb3 = colorbar("Direction","reverse");
ylim(cb3, [-3 1])
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!