Effacer les filtres
Effacer les filtres

colorbar label along y-axis instead of x-axis

11 vues (au cours des 30 derniers jours)
Aomawa
Aomawa le 29 Avr 2024
Commenté : Voss le 2 Mai 2024
Hello! I would like the colorbar label to appear directly underneath the colorbar (right underneath the "220" in the figure below), horizontal along the x axis. However, when I specify this as follows, it aligns the label along the y axis.
Here is the relevant code:
contourf(lon,lat,tmp2, 25, 'LineStyle','none');
hold on
colormap('turbo')
set(gca,'fontsize',14);
ylabel('Latitude (\circ)')
xlabel('Longitude (\circ)')
h = colorbar;
xlabel(h,'(K)');
hold off
------
can someone help me change the orientation of that '(K)', and show me how to adjust my code in general so I can make this adjustments in other plots as well? Thanks.

Réponse acceptée

Voss
Voss le 29 Avr 2024
Modifié(e) : Voss le 29 Avr 2024
% generate random data:
lon = 0:359;
lat = -90:90;
tmp2 = 217+96*rand(numel(lat),numel(lon));
contourf(lon,lat,tmp2, 25, 'LineStyle','none');
colormap('turbo')
set(gca,'fontsize',14);
ylabel('Latitude (\circ)')
xlabel('Longitude (\circ)')
h = colorbar;
xlabel(h,'(K)');
h.Label.Units = 'normalized';
h.Label.Position = [2 0]; % more-or-less centered under the colorbar tick labels
h.Label.Rotation = 0;
Alternatively, you can use
h.Label.Position = [0.5 0]; % centered under the colorbar itself
to center the colorbar label under the colorbar itself, or adjust the first element (or both elements) of that Position as desired.
Position is [x,y] and Units are normalized to the colorbar itself, so [0 0] would place the label at the lower-left of the colorbar, [1 1] would place it at the upper-right, [0 1] would be upper-left, and [1 0] would be lower-right. The label has VerticalAlignment 'top' and Horizontalignment 'center', so the Position is where the top center of the label will be located.
  2 commentaires
Aomawa
Aomawa le 2 Mai 2024
This provided exactly what was needed. Thank you so much!!
Voss
Voss le 2 Mai 2024
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Orange dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by