필터 지우기
필터 지우기

Inconsistancy of colorbars across contourf() plots

조회 수: 1 (최근 30일)
cdlapoin
cdlapoin 2023년 12월 3일
댓글: Voss 2023년 12월 3일
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

채택된 답변

Voss
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 CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by