# Separate y & x axis

11 views (last 30 days)
Paul Hinze on 26 Mar 2022
Commented: Paul Hinze on 1 Apr 2022
Hello,
I would like to separate my y- and x-axis, but i did not find any approach to solve this problem.
The problem in this code is, that the vivsible axis doesnt match the data in the figure. This code is only an attempt, to get in touch with this concept.
Here is the code I tried:
clear
clc
tut_fighandle = figure(1);
tut_fighandle.Position(3) = 700;
tut_axis_a = axes;
tut_axis_a.Position(3) = 1;
tut_axis_a.Position(1) = .1;
tut_fighandle.Color = 'White';
set(tut_axis_a,'XColor','White')
% tut_axis_a.Color = 'White';
t = 0:0.1:10;
f1 = 2*sin(t);
f2 = 0.5*cos(t).*exp(-t)+10;
tut_axis_yypre = axes;
[tut_axis_yy, tut_pyy2, tut_pyy3] = plotyy(t,f2,t,f1);
set(tut_axis_yy,'YColor','White')
box off

Dave B on 27 Mar 2022
There are some submissions on file exchange for this, like this one: https://www.mathworks.com/matlabcentral/fileexchange/57366-separateaxes
Here's a very crude version, this doesn't tie together labels or automatically adjust position, or lots of other niceties, but gives you an idea about how to fake the general effect:
clf
ax=axes('Position',[.12 .12 .85 .85]);
hold on
t=linspace(0,4*pi,100);
plot(ax,sin(t))
ax_x=axes;
ax_x.Position=ax.Position;
ax_x.Position(2)=.07;
ax_x.Position(4)=.00001;
ax_y=axes;
ax_y.Position=ax.Position;
ax_y.Position(1)=.07;
ax_y.Position(3)=.00001;
ax_x.FontSize = ax.FontSize;
ax_y.FontSize = ax.FontSize;
ax.XColor='none';
ax.YColor='none';
ax.XTick=[];
ax.YTick=[];
Paul Hinze on 1 Apr 2022
Very nice! that what it i was looking for. Thank you