How to get the x axis and y axis to start at 0 when adding regression line in Figure window

 採用された回答

I'm assuming you don't want to loose the points with y < 0. Something like this should work...
% test data
x = 1:100;
y = linspace(1,60) + randi([-5 5], 1, 100);
p = scatter(x, y, 'filled');
lsline;
ax = gca;
ax.YLim = [-10 70];
ax.XAxisLocation = 'origin';

3 件のコメント

Stephnie Watson
Stephnie Watson 2021 年 5 月 14 日
There are no values less then 0. It was perfectly matched before adding the regression line. I also have no code as I am using the Figure window for the edits. So I am not sure how I would apply the code?
Scott MacKenzie
Scott MacKenzie 2021 年 5 月 14 日
In that case, look for the XAxisLocation property in the Property Inspector and set it to "origin".
Stephnie Watson
Stephnie Watson 2021 年 5 月 14 日
Thank you, it worked!
Cheers!

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

その他の回答 (1 件)

David Fletcher
David Fletcher 2021 年 5 月 14 日
編集済み: David Fletcher 2021 年 5 月 14 日
Does the axis command do anything:
axis([0 70 0 70])

1 件のコメント

Stephnie Watson
Stephnie Watson 2021 年 5 月 14 日
編集済み: Stephnie Watson 2021 年 5 月 14 日
How would I add the axis code in the Figure window? I don't have any code that I have created. I used create plot then opened the Figures window to add the regression line.

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

製品

リリース

R2021a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by