In Scatter plot, make the largest data on the top

5 views (last 30 days)
Dear Mathwork
I am using "scatter3" to obtain the 4D image with colorbar.
However, only very few data shows in the upper limit region and it will be covered by the other dots( red arrow)
Is there anyway to make sure these "larger" one alway on the top of the figure?
I try to manipulate the sequence of the raw data (matrix) but it did not work.
( The scale of the xlim, ylim or caxis need to be fix like this)
  1 Comment
DGM
DGM on 15 Jan 2022
If you're using scatter3() but you're only using view(2), can't you use the cdata vector to order the points on the depth axis of the plot?
Something like this
N = 1000;
x = rand(N,1);
y = randn(N,1);
c = rand(N,1);
h = scatter3(x,y,c,30,c);
h.MarkerFaceColor = 'flat';
colorbar
view(2)
Markers with higher values on the color scale are closer to the camera.
But if you're using scatter3() for something else, idk what that'd be. I don't know how your data is arranged.

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 15 Jan 2022
Since the data are being plotted with scatter3, experiment with the view function to rotate the 3D figure to display it as desired, since rotating the axes could do that.

Image Analyst
Image Analyst on 15 Jan 2022
Maybe try sorting so that the higher value points are plotted last. Possibly (untested)
% Sort Z so that bigger values are at the bottom.
[zSorted, sortOrder] = sort(z, 'ascend');
% Sort x and y the same way so as to keep rows together.
xSorted = x(sortOrder);
ySorted = y(sortOrder);
cMap = turbo(length(x)); % Make colormap.
scatter3(xSorted, ySorted, zSorted, 30, cMap, 'filled')

Community Treasure Hunt

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

Start Hunting!