how to set position and outerposition respectively the same as from another axes?

15 次查看(过去 30 天)
I want to display a scalebar on a 3d plot. When I rotate the 3d plot, I want to keep the scalebar still. The way I approach it is to create another axes, copying the same xlim, ylim, zlim, etc properties, plot a line as the scalebar, and lastly axis off;
I however encounter a strange problem. It seems not able to set position and outerposition simultaneously the same, which should be doable but I didn't get it yet.
Please help. below is my scalebar function. input h is from h=subplot(231) for example.
function scalebar(h)
obj=findobj('tag','scalebar');
if ~isempty(obj),delete(obj);end
haxes=axes;set(haxes,'tag','scalebar');
ylim=get(h,'ylim');set(haxes,'ylim',ylim);
xlim=get(h,'xlim');set(haxes,'xlim',xlim);
zlim=get(h,'zlim');set(haxes,'zlim',zlim);
ytick=get(h,'ytick');set(haxes,'ytick',ytick);
xtick=get(h,'xtick');set(haxes,'xtick',xtick);
ztick=get(h,'ztick');set(haxes,'ztick',ztick);
DataAspectRatio=get(h,'DataAspectRatio');set(haxes,'DataAspectRatio',DataAspectRatio);
bar_um=10;
line([-0.5 0.5]*bar_um,[0 0],'color','k');
text(-0.3*bar_um,-0.2*bar_um,[ num2str(bar_um) '\mum'],'fontsize',18);
% axis off
axis on;axis vis3d;grid on;view(0,0); % for debug
pos=get(h,'position');
pos(1)=pos(1)+0.05;
pos(2)=pos(2)-0.1;
set(haxes,'position',pos);
axes(h);
clc % below for debug
get(h,'position')
get(haxes,'position')
get(h,'outerposition')
get(haxes,'outerposition')
end

回答(1 个)

Jan
Jan 2012-7-20
No, you cannot set the 'position' and the 'outerposition' to the same value.
Type this in the command window to find the corresponing documentation:
docsearch outerposition
  1 个评论
Chaowei Chen
Chaowei Chen 2012-7-20
Hi Jan, sorry that I should clarify my question. I want to create an axes whose position and outerposition respectively same to that of an existing axes. I have verified that it is manually doable but can't get it done by
pos=get(h,'position');
set(haxes,'position',pos);
opos=get(h,'outerposition');
set(haxes,'outerposition',opos);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by