colorbar label along y-axis instead of x-axis
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1682416/image.png)
0 Kommentare
Akzeptierte Antwort
Voss
am 29 Apr. 2024
Bearbeitet: Voss
am 29 Apr. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Orange finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!