필터 지우기
필터 지우기

Drawing X and Y axis on 2D plot

조회 수: 230 (최근 30일)
David Polcari
David Polcari 2012년 6월 12일
댓글: Sidharth A Narayanan 2023년 3월 22일
Hi everyone,
I have been searching for an easy way to draw the x and y axis on a plot but cannot seem to do it. For example, if I have a plot that has range [-2 10] for x and [-200 400] for y, I would like to be able to draw a line along x = 0 and y = 0. I have looked at certain functions such as axescenter but this draws the axes in the exact center so it does not work for me. The style is great but I can't get it along the axes. Anyone have any ideas?

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 12일
xL = xlim;
yL = ylim;
line([0 0], yL); %x-axis
line(xL, [0 0]); %y-axis
  댓글 수: 10
Zhao Lu
Zhao Lu 2022년 8월 10일
Thanks so much
Sidharth A Narayanan
Sidharth A Narayanan 2023년 3월 22일
I think you interchanged the x-axis and y-axis ...

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Brian Russell
Brian Russell 2021년 4월 30일
Why does everyone give such complicated answers to this question? The answer is xline(0) and yline(0).
  댓글 수: 4
Brian Russell
Brian Russell 2021년 6월 21일
Thanks, Sajib, but I don't know how to move it to the top. I think an administrator has to do that. I think that in an earlier version of MATLAB, the answer at the top was the correct one, but the answer I gave must be a new feature.
Alex Henderson
Alex Henderson 2023년 2월 23일
"Why does everyone give such complicated answers to this question?"
Probably because these functions only appeared in R2018b. Still, useful to know they're there now.

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2016년 9월 1일
As of release R2015b you can set the axes XAxisLocation and YAxisLocation properties to 'origin' to get the axes lines to cross at the origin.
  댓글 수: 1
Ben Ralph
Ben Ralph 2019년 6월 23일
Dead link now I'm afraid.
Now here.

댓글을 달려면 로그인하십시오.


Kajeen Hassan
Kajeen Hassan 2020년 1월 28일
A parametric equation to plot the function x= 1.5 sin(5t), y= 1.5 cos(3t) , plot the function for 0<=t<=2* pi. Format the plot such that the both axes will range from -2 to 2.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by