rotate colorbar tick labels
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Tommy
el 20 de Mayo de 2020
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 comentarios
qizhi yang
el 14 de Nov. de 2024 a las 2:58
Cb.Ruler.TickLabelRotation=40
1 comentario
Walter Roberson
el 14 de Nov. de 2024 a las 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.
Ver también
Categorías
Más información sobre Axis Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!