필터 지우기
필터 지우기

How can I put the axis origin in the middle of the plot?

조회 수: 147 (최근 30일)
Maria Jose Legaz
Maria Jose Legaz 2018년 4월 11일
답변: xin xu 2020년 11월 15일
Hello. I try to do changing the origen of axis to the center of the plot. I have written in matlab:
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
Matlab say: While setting the 'XAxisLocation' property of Axes: 'origin' is not a valid value. Use one of these values: 'bottom' | 'top'.
How can I put the axis origin in the middle of the plot?
I am very grateful if someone can help me Best regards, MJ

채택된 답변

Peter Rochford
Peter Rochford 2018년 4월 28일
If the error you receive is that 'origin' is not a valid or recognized value for the XAxisLocation property, you may be using a release older than release R2015b which is when that value was added as an option for the XAxisLocation property. The alternative for earlier releases is to use PlotAxisAtOrigin.
Note that the labels of the last tick marks disappear when setting the axes location to the origin using
ax.XAxisLocation = 'origin'; ax.YAxisLocation = 'origin';
For a discussion on this problem refer to here. I have yet to find a solution to this problem that will respect axes labeling of font size from a main program such as
set(ax,'FontSize',20);
You can manually insert the tick labels using the text() function but they will not change using the above command. I would prefer MathWorks change the 'origin' feature to respect the same tick labeling as appears when using 'bottom' or 'top'.

추가 답변 (1개)

xin xu
xin xu 2020년 11월 15일
I get a solution, try to use "axis(limits);" command.
For example, I want to plot a line from (-100, 100) to (50, -150). Since abs(-100) > abs(50), set XAxisLocation from -100 to 100. And this also applies to YAxisLocation.
So, add this command into matlab:
axis([-100 100 -150 150]);

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by