Borrar filtros
Borrar filtros

colorbar label along y-axis instead of x-axis

11 visualizaciones (últimos 30 días)
Aomawa
Aomawa el 29 de Abr. de 2024
Comentada: Voss el 2 de Mayo de 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.

Respuesta aceptada

Voss
Voss el 29 de Abr. de 2024
Editada: Voss el 29 de Abr. de 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 comentarios
Aomawa
Aomawa el 2 de Mayo de 2024
This provided exactly what was needed. Thank you so much!!
Voss
Voss el 2 de Mayo de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Orange en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by