I want to add a 45-degree line on my plot. I tried some ways (including refline) all give me a 38-degree line!
조회 수: 82 (최근 30일)
이전 댓글 표시
Hey all
I wanted to have a 45-degree reference line on my plot. I searched and found there is a function namely refline so I use it but as you can see here it renders me a 38-degree line:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/281109/image.jpeg)
I even used
axis equal
but another problem appears. I mean although the line converted to 45 degrees but some space appears on my graph that is not good:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/281110/image.jpeg)
Here is the code that I used:
MONTHLY = scatter(X, Y)
refline
axis equal
As a result, I want something like a black line this graph:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/281111/image.jpeg)
In order to compare trendline (red line) with the perfect condition (45-degree black line).
I attach my X and Y.
Thank you so much
댓글 수: 1
채택된 답변
추가 답변 (2개)
Ameer Hamza
2020년 4월 1일
편집: Ameer Hamza
2020년 4월 1일
Explicitly specify slope with refline
MONTHLY = scatter(X, Y)
refline(1)
axis equal
Or draw both lines
MONTHLY = scatter(X, Y)
r1 = refline;
r1.LineWidth = 1;
r2 = refline(1);
r2.LineWidth = 1;
axis equal
Kouadio Guillaume N'DRI
2022년 1월 22일
편집: Walter Roberson
2022년 1월 23일
In case someone still struggling with this. Find below my suggestion. I had the same problem with the refline.
x1=rand(1,50);
x2=rand(1,50);
scatter(x1,x2)
axis([0 max(max(x1),max(x2)) 0 max(max(x1),max(x2))])
hold on
plot([0 max(max(x1),max(x2))], [0 max(max(x1),max(x2))])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/870125/image.jpeg)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!