Modify x-axis position

丶灬走出姿态 提交于 2019-11-30 22:13:02

Generally, apart from some ugly hackish solutions (can be found on FEX), the functionality you want is not applicable in Matlab. And it doesn't seem so, that it changed with the recent update. So if you really need that, save your figure as vector graphic and edit it with Inkscape or Illustrator, or just draw it with Latex/pgfplots/Matlab2Tikz from the beginning.

However the 2014b update of the graphics engine introduced the following solution using some undocumented features. Maybe this is already sufficient, I dare to say it's the closest you can get without coding handstands.

Matlab R2014b or higher is required!

%// example
t = linspace(0,4*pi);
plot(t,sin(t))
ylim([-1.5,1.5]); xlim([0,4*pi]);

%// get handle
h = gca;

%// modify y-axis
h.YBaseline.BaseValue = 0.5;
h.YBaseline.Visible = 'on'; 
h.XRuler.Axle.Visible = 'off';

%// modify x-axis
h.XBaseline.BaseValue = 2;
h.XBaseline.Visible = 'on';
h.YRuler.Axle.Visible = 'off';

that's a bit trickier than expected because matlab doesn't provide this feature. You could just do it manually by drawing lines and switching off the original axes.

I found some example on the Matlab Central

t=linspace(0,10,100);plot(t,sin(2*pi*t));
axis([-10 10 -1 1]);

y=get(gca,'ytick');
x=get(gca,'xtick');
hold on
Lx=line([x(1) x(11)],[0 0]);
Ly=line([0 0],[y(1) y(11)]);
set(Lx,'color',[1 0 0]);
set(Ly,'color',[1 0 0]);
for i=1:length(x)
    plot(x(i),0,'k*',0,y(i),'k*');
    text(x(i),-.05,num2str(x(i)));
    text(-1,y(i),num2str(y(i)));
end
set(gca,'yticklabel',[],'xticklabel',[],'ytick',[],'xtick',[]);
set(gca,'visible','off')

but you should also check on fileexchange as there is probably some better solution already around.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!