rotate colorbar tick labels
23 次查看(过去 30 天)
显示 更早的评论
I have the following which generates a colorbar. However, the orientation of the tick labels means that if the font is increased they will run together. Thus I need to rotate the tick lables in order to make them bigger *and* still legible
figure;
tiledlayout(1,1);
skipticks = 3;
t1=nexttile;
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
offset = rand(1)*1e-6;
Z = Z*1e-14 + offset;
pcolor(X,Y,Z)
cmorig = colormap(gca);
view(2)
colorbar('southoutside');
Result:
What I need:
0 个评论
回答(2 个)
Tommy
2020-5-20
You could place the labels yourself using text. Personally, I'd rather MATLAB figure out the placement.
Here's code which puts a set of invisible axes on top of the colorbar, turns the colorbar tick labels off, and instead shows labels for the axes ticks. The axes ticks are placed where labels previously existed in the colorbar. Then xtickangle rotates the labels.
figure;
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
offset = rand(1)*1e-6;
Z = Z*1e-14 + offset;
pcolor(X,Y,Z)
cmorig = colormap(gca);
view(2)
% changes/additions start here
cb = colorbar('southoutside');
keepLabels = ~cellfun(@isempty,cb.TickLabels);
cb.TickLabels = [];
ax = axes('Position', cb.Position,...
'Color', 'none',...
'YTick', [],...
'XLim', cb.Limits,...
'XTick', cb.Ticks(keepLabels),...
'FontSize', cb.FontSize);
xtickangle(ax, -30);
The result is this:
Of course repositioning the colorbar will mess it up. You may need to manually reposition some things yourself to keep the 'x 10^-n' within the figure.
This may be overcomplicated, but I wasn't sure how else to do it without placing the labels yourself. Hopefully this works for you!
0 个评论
qizhi yang
2024-11-14,2:58
Cb.Ruler.TickLabelRotation=40
1 个评论
Walter Roberson
2024-11-14,3:33
This is the way, when it is understood that
Cb = colorbar('southoutside');
The one small thing: the TickLabelRotation should be set to roughly -45 to match the original request.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!