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

9 views (last 30 days)
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)

Accepted Answer

dpb
dpb on 20 Aug 2020
Edited: dpb on 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...

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!