# How do I use matlab to plot a graph where the x,y axes do not intersect?

11 views (last 30 days)

Show older comments

### Accepted Answer

Jonas
on 28 Apr 2021

not elegant, but possible if i'm not mistaken:

fig=figure;

% amount of shift of x and y axis in normalized coordinates

dx=0.05;

dy=0.05;

plotAx=axes('Position',[0.1 0.1 0.85 0.85],'Color','none');

% create shifted y axis

yax=axes('Position',plotAx.Position-[dx 0 -dx 0],'Color','none','XColor','none');

yax.XGrid='off';

% create shifted x axis

xax=axes('Position',plotAx.Position-[0 dy 0 -dy],'Color','none','YColor','none');

xax.YGrid='off';

axes(plotAx); % set curr axis

% plot sample data

x=-2:0.1:2;

y=(x-1).^2+1;

plot(plotAx,x,y)

grid off;

linkaxes([plotAx,yax,xax]);

yticklabels([]);

xticklabels([]);

% remove rulers

plotAx.XColor='none';

plotAx.YColor='none';

##### 5 Comments

Adam Danz
on 30 Apr 2021

### More Answers (1)

Bob Thompson
on 27 Apr 2021

Create your figure first, then create the axes. This will allow you to specify what they are before the data gets populated, and should allow you to fix their positions.

I have not looked at the documentation in enough detail to confirm it will do exactly what you want, but it should be in the axes command.

##### 2 Comments

Adam Danz
on 28 Apr 2021

### See Also

### Community Treasure Hunt

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

Start Hunting!