Crossing axis and labels in matlab

浪子不回头ぞ 提交于 2019-12-24 04:49:05

问题


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 ?


回答1:


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

  • PlotAxisAtOrigin by Shanrong Zhang
  • axescenter by Matt Fig

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




回答2:


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';

Example is taken from MATLAB official documentation:

  • Display Axis Lines through Origin
  • Controlling Axis Location


来源:https://stackoverflow.com/questions/6321424/octave-matlab-force-axes-to-cross-at-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!