How to set scatter plot colors in order to adjust all plots to a same reference?

65 views (last 30 days)
Hi all,
I am intending to define the color of my scatter plots based on the same reference for "zaxis", lets suppose [8*10^-5,8*10^-3]. The code that I applied just changed the scale of the color bar, but did not change the color on the plot. I would like to change the colors of the plots to values higher than the [max(z), min(z)] and also to do another plot based on values lower than the max and min. To sum up, the scatter plot have exhibited just max and min colors automatically.
I tried
%
axis manual
axis([min(position), max(position), min(depth), max(depth), 8*10^-5, 8*10^-3,8*10^-5, 8*10^-3])
colorbar
and also
%
colorbar
caxis([ 8*10^-5 , 8*10^-3])
I tried other intermediary values between "min and max" and higher than "min and max", but the representation of the plot still reconfigured to the min and max.
Thank you for your time,

Accepted Answer

Mike Garrity
Mike Garrity on 30 Sep 2015
I'm not sure I'm following. Let's take a simple, concrete example:
rng default
nval = 100;
cmin = 8e-5;
cmax = 8e-3;
c = cmin + (cmax-cmin)*rand(1,nval);
x = randn(1,nval);
y = randn(1,nval);
scatter(x,y,[],c,'filled')
colorbar
At this point, caxis returns
ans =
0.000174264390450 0.007767094831544
Because those are the min & max values in the array c. If we do this:
caxis([cmin, cmax])
Then the colorbar and the mapping the scatter uses to go from the array c to color values stretches to make room for the entire range.
That's kind of hard to see because the range is small. If we move one of the limits way in, it becomes more obvious.
caxis([cmin, cmax/2])
Notice how all of the scatter values in the top half of the range are now drawn in the yellow color at the top of the colormap. Is that different from what you've encountered, or did you expect something different?
  1 Comment
Ryan Alicea
Ryan Alicea on 13 Aug 2018
Hi Mike,
I am trying to do something similar as this to a series of scatter3 plots, however, adjusting the caxis limits has no effect on the scatter colors themselves, only the text appearing next to the colorbar. Do you have any idea as to why this could be? Here is an example of my process. I am using R2017a.
Q_nrml = Q/max(limit);
[~, sortIndexes1] = sort(Q_nrml);
C = jet(length(Q_nrml));
figure(1)
scatter3(X(sortIndexes1), Y(sortIndexes1), Z(sortIndexes1), 15, C, 'filled');
colormap(C)
caxis([min(limit) max(limit)]);
c = colorbar;
The color of the data is still scaled according to itself instead of the limits set by caxis. caxis is only changing the labeling of the colorbar, not the plot itself.
Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps 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!