MATLAB Answers

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

조회 수: 4(최근 30일)
cui
cui 2021년 4월 27일
댓글: Adam Danz 2021년 4월 30일
How can I use matlab to plot a graph where the x,y axes do not intersect? Similar to the image below, note that the bottom left corner does not cross.The x- and y-axes are shown with specified ranges
  댓글 수: 5
cui
cui 2021년 4월 29일
Oh, what I meant to say was that I hope that future versions will enhance the personalisation of axes properties.
PS: I am not very good at English, sorry

댓글을 달려면 로그인하십시오.

채택된 답변

Jonas
Jonas 2021년 4월 28일
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
Adam Danz
Adam Danz 2021년 4월 30일
I'm not so sure disconnected axes is a very popular idea. What's the benefit of doing this, by the way? Curious.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Bob Thompson
Bob Thompson 2021년 4월 27일
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
Adam Danz
Adam Danz 2021년 4월 28일
cui is correct here. There are no axes properties that can achive this. There are, however, undocumented ruler properties that can achieve at least some of it.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by