필터 지우기
필터 지우기

Add a 45-degree line in a log-glog plot

조회 수: 5 (최근 30일)
Md Mia
Md Mia 2023년 1월 6일
댓글: Md Mia 2023년 1월 7일
Hi
I have a scatter plot as below:
scatter(log(X(:,1)),log(X(:,2)))
I want to add a 45-degree line here. I tried using refline(1,0) and got followint fig. Does it okay or refline can't be used in log-log plot. Please help.

채택된 답변

Voss
Voss 2023년 1월 6일
Well, that's not a log-log plot; both axes are linear.
The line does indeed have slope 1. It may not be apparent that the slope is 1 because the x- and y-scales are different. (Notice that the distance from 19 to 20 on the x-axis is about twice as many screen pixels as the distance from 19 to 20 on the y-axis.)
  댓글 수: 4
John D'Errico
John D'Errico 2023년 1월 7일
@Md Mia - your confusion stems from the fact that IF the axis scaling is not the same for x and y, then a 45 degree line will not look like it is 45 degrees.
Let me give you an example.
x = [0 1];
y = [0 1];
Do you agree that the curve represented by those points MUST be a slope of 1? So the line would be perfectly 45 degrees? Now I'll plot those points TWICE, but I'll change the axes.
plot(x,y,'-')
xlim([-1 2])
ylim([0,1])
plot(x,y,'-')
xlim([0,1])
ylim([0,1])
axis equal
axis tight
The second plot was created to have the same spacing on the x and y axes. (Though, strangely, the y axis can sometimes have a different set of tick marks than x. Sigh.)
But do you agree that the first plot does not look remotely as if it has a 45 degree slope? In fact, it does have a perfectly 45 degree slope, but only when viewed properly. Screw around with the axis scaling, and nothing will look right. The data was the same on both plots.
Now, refline(1,0) DOES create a 45 degree line. But if you use it to plot a line on a set of axes where the units are differently scaled, then you get something that will look wrong, no matter what. That does not make it wrong. It is just your perception of wrong-ness that will be the problem.
Md Mia
Md Mia 2023년 1월 7일
Thanks for the clarifications. I understood now. Changed my scaling and look better although previously also it was okay. Thank you John D'Errico for your excellent explanations.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by