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

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 commentaires

Jonas
Jonas le 27 Avr 2021
Modifié(e) : Jonas le 27 Avr 2021
I don't know the smart solution, but you could generate an axis where you plot you dara but you hide y and x axis. before that you have to create two other axis, in one you hide the y axis in the other the x axis. these to axes have to be shifted in position compared to the plotting axis. then you can link the axes such that plotting in the axis with hidden x and y has an influence on the 'helper' axes
This will likely require a deep dive into undocumented methods. It will require making changes to the xruler and yruler, both of which are properties of axes.
So look out for future versions with more axes to customise and personalise
> So look out for future versions with more axes to customise and personalise
@cui, what does that mean?
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

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

Set tickdir to out.
I've come up with a solution that moves the x-axis line and ticks and I figured out how to move the tick labels but they are in different units so I need more time to think about that which won't happen anytime soon but maybe someday I'll update this with a new answer.
@Adam DanzI'm very glad to hear that! But I personally think that these "basic issues" should be left to the mathworks development engineers, and that the new version should enhances these shortcomings.
I'm not so sure disconnected axes is a very popular idea. What's the benefit of doing this, by the way? Curious.

Connectez-vous pour commenter.

Plus de réponses (1)

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 commentaires

I can't find any customisation of axes properties related to axis position lengths etc. in the axes properties rulers, not in the documentation at the moment.
It would be nice to have a concrete and elegant code implementation.
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by