How to shift scatter() to origin (0,0) on a plot with recorded data
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
dpb
el 20 de Ag. de 2020
Editada: dpb
el 20 de Ag. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Scatter Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!