colorbar label along y-axis instead of x-axis
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2024-4-29
编辑:Voss
2024-4-29
% 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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!