I have a wide range of values and while plotting as a scatter(x,y,z), the colorbar showing the z axis shows a wide range of values, now I am not interested in the lower range values. Is there any method to change the range in color bar. I have the following part of my code to plot, I also intend to plot the log plot. For eg. I want to set the range in my log plot to 14 to the maximum value.
I want some values not to be displayed at all. so that the color bar has a limited range, say from 14 to maximum. At present it is showing from 9 to maximum in the log plot.
scatter(x(1:end-1), y(1:end-1), 5, gnd);
title('G plot (m^-^2)');
colorbar('eastoutside');
xlabel(' X-axis (microns)');
ylabel('Y-axis (microns)');
figure;
log_g=log10(gnd);
scatter(x(1:end-1), y(1:end-1), 5,log_g);
colorbar('eastoutside');
xlabel(' X-axis (microns)');
ylabel('Y-axis (microns)');
title('G Density, log plot (m^-^2)');
I believe that caxis
is the command you're looking for. Usage:
caxis([minValue maxValue])
Using caxis
like this, all values outside the range [minValue maxValue]
will be coloured with the lowest or highest value in the colormap, respectively.
Since colorbar
and friends use colormap
, you'll have to adjust the current colormap if you want to adjust the number of colors used. Do this like so:
%# get current colormap
map = colormap;
%# adjust for number of colors you want
rows = uint16(linspace(1, size(map,1), NUM_COLORS)) ;
map = map(rows, :);
%# and apply the new colormap
colormap(map);
Of course, combining this with caxis
is the most powerful.
If you don't want to show some values outside of range, that's not a job for colorbar
or caxis
, that's up to you -- you'll have to adjust the data that's plotted so that all values you don't want plotted are NaN
. Doing so will make Matlab understand that you don't want to plot these data:
data( indices_to_data_not_to_plot ) = NaN;
surf(x,y,data); %# or whatever you're using