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

9 次查看(过去 30 天)
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)

采纳的回答

dpb
dpb 2020-8-20
编辑:dpb 2020-8-20
'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 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by