Azzera filtri
Azzera filtri

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

5 visualizzazioni (ultimi 30 giorni)
Md Mia
Md Mia il 6 Gen 2023
Commentato: Md Mia il 7 Gen 2023
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.

Risposta accettata

Voss
Voss il 6 Gen 2023
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 Commenti
John D'Errico
John D'Errico il 7 Gen 2023
@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 il 7 Gen 2023
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by