Crossing axis and labels in matlab

2019-01-23 19:44发布

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 ?

2条回答
ゆ 、 Hurt°
2楼-- · 2019-01-23 20:27

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).

查看更多
可以哭但决不认输i
3楼-- · 2019-01-23 20:47

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:

查看更多
登录 后发表回答