6

I just can't find it. How to set up axis and labels in matlab so they cross at zero point, with the labels just below the axis not on left/bottom of the plot ?

If I didn't make myself clear - I just want the plot to look like like we all used to draw it when in school. Axes crossing, 4 quadrants, labels right below axis, curve ... as it goes.

Anyone knows how to set it up ?

Amro
  • 123,847
  • 25
  • 243
  • 454
Rook
  • 60,248
  • 49
  • 165
  • 242
  • 1
    To clarify, Idigas wants the plot to look like http://upload.wikimedia.org/wikipedia/commons/3/37/IdempotentCosineAngle.jpg (I think). – Jitse Niesen Sep 23 '09 at 15:29
  • @Jitse Niesen - exactly. While I was searching for the image, you already found it. – Rook Sep 23 '09 at 15:41

2 Answers2

7

You should check out two submissions on The MathWorks File Exchange:

Hopefully these will work with whatever MATLAB version you have (the submission from Matt Fig is the most recently updated one).

gnovice
  • 125,304
  • 15
  • 256
  • 359
  • @Idigas: I understand what you want now. I updated my answer accordingly. – gnovice Sep 23 '09 at 15:52
  • Hmm, yes I found the first one (the image "upstairs" is from it. But I've been having problems with it when manipulating it.). They both seem like workarounds to me ... do you mean to tell me matlab doesn't support something like this normally ? ... checking out the second one. – Rook Sep 23 '09 at 15:54
  • @Idigas: There's nothing like this currently built-in to MATLAB. You either have to create this sort of thing yourself or find a FEX submission from someone who already has. ;) – gnovice Sep 23 '09 at 16:11
  • Good to know. Anyway, I managed to get the second one working, so that will have to do for now. Appreciate the help in clearing this out for me. – Rook Sep 23 '09 at 16:16
3

As of Matlab release R2015b, this can be achieved with the axis property XAxisLocation and YAxisLocation being set to origin.

In other words,

x = linspace(-5,5);
y = sin(x);
plot(x,y)

ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';

Axes through origin, from Matlab official documentation

Example is taken from MATLAB official documentation:

Amro
  • 123,847
  • 25
  • 243
  • 454
David_G
  • 1,127
  • 1
  • 16
  • 36
  • 3
    +1, one thing to note, it only works for 2D views. One [linked question](https://stackoverflow.com/q/6321424/97160) asks about 3D axes, in which case the above properties have no effect. – Amro Jun 03 '17 at 23:41