I want to add a 45-degree line on my plot. I tried some ways (including refline) all give me a 38-degree line!
181 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
BN
am 1 Apr. 2020
Bearbeitet: Walter Roberson
am 23 Jan. 2022
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:
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:
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:
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 Kommentar
Walter Roberson
am 1 Apr. 2020
axis equal is right. You might need to use xlim() or ylim() afterwards
Akzeptierte Antwort
Weitere Antworten (2)
Ameer Hamza
am 1 Apr. 2020
Bearbeitet: Ameer Hamza
am 1 Apr. 2020
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
am 22 Jan. 2022
Bearbeitet: Walter Roberson
am 23 Jan. 2022
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))])
0 Kommentare
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!