필터 지우기
필터 지우기

suggest me how to plot 45 degree line in MATLAB?

조회 수: 23 (최근 30일)
SAGAR PATEL
SAGAR PATEL 2019년 2월 22일
편집: John D'Errico 2020년 1월 11일
how can I plot a line with 45 degree angle in the graph as reference line????
when I use the code "refline" the line I got different angle line and I want 45 degree angle line from the centre of both axes so please suggest me how can I get.
  댓글 수: 2
Jan
Jan 2019년 2월 22일
Please post the code, when you mention it. What is "the center of both axes"?
SAGAR PATEL
SAGAR PATEL 2019년 2월 23일
I mean, I want 45 degree reference line. can I get that by give the same axis limit????

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

채택된 답변

Jan
Jan 2019년 2월 22일
I guess, that you do get a 45 deg angle, but that the different scaling of X and Y axes let it look in another angle. See:
axis equal
to use the same scaling for both directions.
  댓글 수: 2
SAGAR PATEL
SAGAR PATEL 2019년 2월 23일
so I have to give same axis limit is it right????
Stephen23
Stephen23 2019년 2월 23일
편집: Stephen23 2019년 2월 23일
"so I have to give same axis limit is it right"
That depends...
To a get a 45 degree line in the data space, the axis limits are irrelevant.
If you are trying to get a 45 degree line on the screen (rather than in the data space and without using equal axis) you would need to get the displayed size of the axes and your screen resolution and figure it out the required data from that. Then the limits might be useful.

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

추가 답변 (1개)

Pankaj Dey
Pankaj Dey 2020년 1월 11일
Hope this will help you.
hline = refline([1 0]);
hline.Color = 'k';
hline.LineStyle = ':';
hline.HandleVisibility = 'off';
Source: https://fanwangecon.github.io/M4Econ/graph/main/fs_lines.html
  댓글 수: 2
John D'Errico
John D'Errico 2020년 1월 11일
편집: John D'Errico 2020년 1월 11일
You still need to define the axes to have the same units. So your suggestion will fail, unless you also specify
axis equal
As proof of that fact, consider what happens if you do EXACTLY as you have suggested.
hline = refline([1 0]);
hline.Color = 'k';
hline.LineStyle = ':';
hline.HandleVisibility = 'off';
The line appears to lie at roughly a 35-40 (actually 38 degrees from a quick check) degree angle, or so. It is CLEARLY not at 45 degrees. The problem arises because MATLAB does not create a plot with equal axes. You can think of it by seeing the tick marks are a little farther apart on the screen on the x axis, per unit traveled. The result? The line does not appear to be at 45 degrees. While it really is a 45 degree line, it does not look like one.
Now however, add one more command:
axis equal
Now the line clearly lies at a 45 degree angle, and all is good in the world. Nothing has really changed from what you showed how to do, but the line is now seen to lie at 45 degrees on the screen.
Pankaj Dey
Pankaj Dey 2020년 1월 11일
Thank you for your clarification !

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

카테고리

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