lsline shifts the yaxis upwards

I am plotting four points:
x = [-0.13; -0.31; -1.07; -0.85] y = [-2.58; 5.21; -0.80 ; -1.14]
plot (x,y,'o')
x-axis and y-axis minimum and maximum should be same (both axes should have same scale) Here, -3 is minimum limit and 6 is maximum limit for both x and y axes.
I use lsline function to plot the least square fit line. Though both axes have same scale, however the y axis shifts upwards. ( -3 the minimum point on y axis shifted upwards)
Y-axes has less distance between the tick points. Please see the figure.
I don't know why? Please help.

 採用された回答

Paul
Paul 2014 年 2 月 24 日

0 投票

add:
axis([-3 6 -3 6],'square')
after your plot command.

7 件のコメント

Priya
Priya 2014 年 2 月 24 日
編集済み: Priya 2014 年 2 月 24 日
Hi
Thanks. I tried.
Its converting the figure into square shape, however there is no change in the axis shift.
I used the following code:
x = [-0.13; -0.31; -1.07; -0.85];
y = [-2.58; 5.21; -0.80 ; -1.14];
f = figure;
plot(x,y,'o')
axis([-3 6 -3 6]);
set(gca,'YTick',[-3:1:6]);
set(gca,'XTick',[-3:1:6]);
grid on
l_line = lsline;
Please see the figure.
Paul
Paul 2014 年 2 月 24 日
編集済み: Paul 2014 年 2 月 24 日
You should put the axis command after the lsline command:
x = [-0.13; -0.31; -1.07; -0.85]; y = [-2.58; 5.21; -0.80 ; -1.14]
plot (x,y,'o')
grid on;
lsline
axis([-3 6 -3 6],'square')
Figure:
Priya
Priya 2014 年 2 月 25 日
Its strange. I am using the following code strictly. Its giving the following incomplete figure.
x = [-0.13; -0.31; -1.07; -0.85];
y = [-2.58; 5.21; -0.80 ; -1.14]
plot (x,y,'o')
grid on;
lsline
axis([-3 6 -3 6],'square')
Paul
Paul 2014 年 2 月 25 日
Running the axis command both before the lsline command and after it, fixes that:
axis([-3 6 -3 6],'square')
lsline
axis([-3 6 -3 6],'square')
Priya
Priya 2014 年 2 月 25 日
Thanks it worked.. Why did this happen ?
Paul
Paul 2014 年 2 月 25 日
I think it's just a bug. I tried it in Matlab r2013b and it worked with just one axis command, whereas in r2012b I had the same problem as you. I think it resizes the line from the x value of the first point to the most right point.
Tony Ingram
Tony Ingram 2017 年 3 月 28 日
This is still happening in 2016b... how can we report this to get it fixed?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2014 年 2 月 24 日

コメント済み:

2017 年 3 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by