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!