필터 지우기
필터 지우기

rotate colorbar tick labels

조회 수: 28 (최근 30일)
mkarikom
mkarikom 2020년 5월 19일
답변: Tommy 2020년 5월 20일
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:

답변 (1개)

Tommy
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!

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by