Add a 45-degree line in a log-glog plot
15 ビュー (過去 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!