MATLAB Answers

How to shift scatter() to origin (0,0) on a plot with recorded data

조회 수: 8(최근 30일)
Taylor Knuth
Taylor Knuth 20 Aug 2020
편집: dpb 20 Aug 2020
I am using the scatter() function to plot time versus force input from a recorded input and I want to center the results from the scatter plot to origin (0,0). What is the best way to recenter my scatter plot?
Test1=importdata('scatterdata.txt');
Test1=scatterdata.data;
X=Test1(:,1); %Magno X
Y=Test1(:,2); %Magne Y
figure
scatter(X,Y)

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 20 Aug 2020
편집: dpb 20 Aug 2020
'Pends on what "center" and "best" mean... :)
Normally, I'd say just
test=readmatrix('scatterdata.txt');
figure
testmn=mean(test);
hSc=scatter(test(:,1)-testmn(1),test(:,2)-testmn(2));
but on trying that, one gets a somewhat unexpected result:
The problem is your sampling is so overloaded to the lower RH quadrant --
It's not just a few over the average elsewhere but those four bins are like 8-10X the number of observations as the upper end of the others so the means are grossly weighted in that direction.
Again depending upon what is desired, you could either then visually select a shift of the origin offset or, with some effort, compute a weighted mean from the histogram counts and bin centers to counteract the samping discrepancy and shift the mean to more nearly the geometric centroid.
Or, you could try simply using the bounding box means...as a thought just comes to mind--
midxy=mean([max(test);min(test)]);
figure
scatter(test(:,1)-midxy(1),test(:,2)-midxy(2))
hAx=gca;
hAx.XAxisLocation='origin';hAx.YAxisLocation='origin';
box on
That's probably closer to what you had in mind...

  댓글 수: 0

댓글을 달려면 로그인하십시오.

추가 답변(0개)

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by