Add a 45-degree line in a log-glog plot
조회 수: 5 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!