Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set the range in the colorbar manually?

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)');
like image 594
rcty Avatar asked Oct 04 '12 02:10

rcty


People also ask

How do I set the range in Colorbar?

Use the vmin and vmax Parameter to Set the Range of Colorbar in Python. The vmin and vmax parameters can be used to specify the scale for mapping color values. These parameters work with the object, which uses colormaps. It can be used to control the range of the colorbar in matplotlib.

How do I change the tick size in Colorbar?

Create a colorbar with a scalar mappable object image. Initialize a variable for fontsize to change the tick size of the colorbar. Use axis tick_params() method to set the tick size of the colorbar.

How do I change the color bar in Matplotlib?

You can change the color of bars in a barplot using color argument. RGB is a way of making colors. You have to to provide an amount of red, green, blue, and the transparency value to the color argument and it returns a color.


1 Answers

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
like image 141
Rody Oldenhuis Avatar answered Nov 08 '22 08:11

Rody Oldenhuis