How to select one point as the center of the plot
15 views (last 30 days)
Show older comments
Hi I have a 3d scatter plot where I can select specific datasets in my table
ix=iswithin(T.Num,12,25)
hSc3 = scatter3(T.CED(ix),T.r(ix),T.E0(ix),'filled');
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
end
My question is, what would I need to do to select a specific element to be the center of the plot (i.e. a specific "ix" as the origin) and everything else i splotted around it.
Please let me know, thanks!
5 Comments
Star Strider
on 1 May 2023
If I understand your question correctly, I would get the values of that point’s (x,y,z) coordinates, and subtract those values from every point in the plot. That point becomes the centre, and all the others shift appropriately.
Accepted Answer
DGM
on 1 May 2023
Edited: DGM
on 1 May 2023
I see two answers, depending on the interpretation of the question.
Perhaps you want to center a reference point in the axes.
% generate some fake data
rng(123)
n = 20;
x = rand(n,1);
y = rand(n,1);
z = rand(n,1);
% specify reference point
refidx = 6;
ref = [x(refidx) y(refidx) z(refidx)];
% create the scatter plot
scatter3(x,y,z,30,z,'filled');
% mark the reference point for clarity
hold on
plot3(ref(1),ref(2),ref(3),'+','markersize',10)
% adjust limits so that marker is centered in the axes
xlim(ref(1) + [-1 1]*max(abs(xlim - ref(1))));
ylim(ref(2) + [-1 1]*max(abs(ylim - ref(2))));
zlim(ref(3) + [-1 1]*max(abs(zlim - ref(3))));
Or perhaps you want to shift all the points such that the reference point is at [0 0 0]
% generate some fake data
rng(123)
n = 20;
x = rand(n,1);
y = rand(n,1);
z = rand(n,1);
% specify reference point
refidx = 6;
ref = [x(refidx) y(refidx) z(refidx)];
% offset the data
xos = x-ref(1);
yos = y-ref(2);
zos = z-ref(3);
% create the scatter plot
scatter3(xos,yos,zos,30,z,'filled');
% mark the reference point for clarity
hold on
plot3(0,0,0,'+','markersize',10)
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!