MATLAB: Whats wrong with this 45 degree line on the plot

MATLABplot

Hey all, I wanted to have a 45-degree line on my plot in order to have a background for comparing with the trend line of forecasted. I used this code in order to make this 45 degree line:
class1 = scatter(X,Y,12,'k','filled');
plot(1:max(X),'k'); %45 degree line (black)
plot(1:max(X),pp(1)*(1:max(X))+pp(2)); %trend line
In some of my data, everything is okay but in others, I achieve this figure:
I don't know why this happens. I want to have a black line in 45 degrees and trend line corresponding to it just like this picture below:
(Black is the 45-degree line and red is trend line)
Could anyone help me?
Thanks

Best Answer

Appearances can be deceiving. Why do you think the line is NOT at 45 degrees? (I know, silly question, but there is a point in it.)
In fact, a 45 degree line merely means that the rise and run are the same. That is, if you change x by some number deltax, then y changes by exactly the same amount. Does that not happen in your plot? I know. You still do not see it.
So what is happening here? The units on the x and y axes are not the same. I'll create two plots as an example.
plot(rand(5),rand(5),'ko')
hold on
plot([0 1],[0 1],'r-')
axis equal
Does the line appear to be at 45 degrees? We know it is, and it looks like it is.
Now, just change the axis scaling. The numbers are still identically the same.
axis normal
axis([0 1 0 2])
Does it look like a 45 degree line now?
In this context, look at the axes on the plot you show. Are the axes scaled the same way?
Related Question