Effacer les filtres
Effacer les filtres

Inconsistancy of colorbars across contourf() plots

2 vues (au cours des 30 derniers jours)
cdlapoin
cdlapoin le 3 Déc 2023
Commenté : Voss le 3 Déc 2023
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

Réponse acceptée

Voss
Voss le 3 Déc 2023
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])
  2 commentaires
cdlapoin
cdlapoin le 3 Déc 2023
Thank you!
Voss
Voss le 3 Déc 2023
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by