How to set the limits of a colorbar for scatter3?

9 views (last 30 days)
I am trying to make a 3D scatter plot where the colors of the dots are a fourth piece of information in the graph and therefore is independent of the x, y, and z axes. Right now my code is:
scatter3(sub_1_x, sub_1_y, sub_1_z, [], sub_1_c)
But I would like to set the limits of sub_1_c such that it ranges from -1.15e3 to 1.0e3. How can I do this since the colorbar is independent of the x, y, and z axes?
Thank you!

Accepted Answer

Walter Roberson
Walter Roberson on 26 Feb 2018
You can use caxis() to set the limits of values used in color computation.
Or you could use pass
min( max( sub_1_c, 1.0e3), 1.15e3 )
instead of sub_1_c
However, now I am wondering if you are asking for the color bar to be reversed, so that the largest value is at the bottom and the smaller value is at the top? If so then you would
cb = colorbar();
cb.YDir = 'reverse';
  3 Comments
Walter Roberson
Walter Roberson on 26 Feb 2018
caxis([-1.15e3, 1.0e3])
or
adjusted_sub1c = max( min( sub_1_c, 1.0e3), -1.15e3 ); %I keep getting the order confused myself!
scatter3(sub_1_x, sub_1_y, sub_1_z, [], adjusted_sub1c);

Sign in to comment.

More Answers (0)

Categories

Find more on Color and Styling 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!