フィルターのクリア

How can I change the position of the numbers in colorbar?

33 ビュー (過去 30 日間)
yogan sganzerla
yogan sganzerla 2018 年 8 月 2 日
編集済み: jonas 2018 年 8 月 7 日
Dear, I would like to define the position of the number in that I have in colorbar.
To explain better, I am adding an image to show what I have and what I would like to have. This is the image.
Be attention on the 300ºC!
Cheers!
  6 件のコメント
jonas
jonas 2018 年 8 月 6 日
編集済み: jonas 2018 年 8 月 6 日
Correct me if I am wrong, but I believe you have actually rotated this image before uploading. In reality you want a horizontal colorbar with vertical ticklabels, yes?
As Adam Danz pointed out, the default text orientation on colorbars is always horizontal, but you want vertical right?
Adam Danz
Adam Danz 2018 年 8 月 6 日
編集済み: Adam Danz 2018 年 8 月 6 日
...or do you want a vertical colorbar with horizontal ticks? That one's easy:
h=colorbar('southoutside');
I don't know of a way to rotate the tick marks of a colorbar.

サインインしてコメントする。

回答 (1 件)

jonas
jonas 2018 年 8 月 6 日
編集済み: jonas 2018 年 8 月 7 日
Rotating the ticklabels are surprisingly difficult. Ticklabels can not be rotated, but they can be replaced by normal text which in turn can be rotated. Here is a function to rotate the ticklabels of any colorbars with linear scale. Report back to me if you find any bugs. The ticklabels will always be on the right side (vertical) or below (horizontal) the colorbar.
function CTixRotate(cb)
cb.TickLabels={}
%%Grab some position properties for later use
ax_pos=get(gca,'position')
ax_limx=get(gca,'XLim')
ax_limy=get(gca,'YLim')
cb_pos=get(cb,'position')
cb_lim=get(cb,'limits')
%%Grab colorbar ticks
tix=cb.Ticks;
%%Create cell array with ticklabels
tixlabels=sprintfc('%.2g',tix)'
%%Normalized coordinates for ticks
%%Vertical colorbar
if cb_pos(4)>cb_pos(3)
ny=linspace(cb_pos(2),cb_pos(2)+cb_pos(4),numel(tix))';
nx=repmat(cb_pos(1)+cb_pos(3),numel(tix),1)
%%Horizontal colorbar
else
nx=linspace(cb_pos(1),cb_pos(1)+cb_pos(3),numel(tix))';
ny=repmat(cb_pos(2),numel(tix),1)
end
%%Convert from normalized (nx,ny) to axes (x,y) coordinates
ky=(diff(ax_limy)/((ax_pos(2)+ax_pos(4))-ax_pos(2)));
kx=(diff(ax_limx)/((ax_pos(1)+ax_pos(3))-ax_pos(1)));
y=ky.*ny-ky*ax_pos(2)+ax_limy(1);
x=kx.*nx-kx*ax_pos(1)+ax_limx(1);
%%Write out ticklabels
if cb_pos(4)>cb_pos(3)
ht=text(x,y,tixlabels',...
'rotation',-90,'verticalalignment','bottom','horizontalalignment','center')
else
ht=text(x,y,tixlabels',...
'rotation',-90,'verticalalignment','mid','horizontalalignment','left')
end
end
Example:
cb=colorbar;
cb.Position=[.5 .3 .05 .6];
caxis([5 10])
axis([2 7 90 100])
CTixRotate(cb)

カテゴリ

Help Center および File ExchangeColorbar についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by