Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change matlab colorbar scaling

I am having a really hard time understanding how to change the range of my colorbar in Matlab2015b.

By default it will range from 0 to 1. I managed to change the label by using:

    c=colorbar;
    c.Limits=[0 180] % the range that I want

The problem is the colors don't scale when I do that, in other words it will display from 0 to 180 but still uses the colors associated to [0 1], which makes look the the whole bar like one color.

enter image description here

I used another approach by just changing the ticks and doing:

colorbar('Yticks',[0:10:180]).

Again, the colorbar is still associated to 0 to 1, so none of the ticks except 0 will appear as the first one starts at 10.

enter image description here

How do I change the data it is based on ? I tried changing c.UserData but it doesn't do anything.

like image 745
Kevin Héritier Avatar asked Nov 11 '15 12:11

Kevin Héritier


People also ask

How do you rescale Colorbar in Matlab?

Direct link to this commentc = colorbar; c. TickLabels = linspace(0,1,numel(c. Ticks));

How do you change scale color in Matlab?

You can change the color scheme by specifying a colormap. Colormaps are three-column arrays containing RGB triplets in which each row defines a distinct color. For example, here is a surface plot with the default color scheme. f = figure; surf(peaks);

What does Caxis do in Matlab?

caxis controls the mapping of data values to the colormap. It affects any surfaces, patches, and images with indexed CData and CDataMapping set to scaled. It does not affect surfaces, patches, or images with true color CData or with CDataMapping set to direct.


1 Answers

From your comment, I see what you are trying to do.

You are on the right lines setting ytick, but as you noticed this only changes the position of the ticks on your colorbar, but the scaling stays the same. Instead, try to set yticklabel:

% Show the colorbar
c = colorbar;

% Define the desired ticks
ticks = [0:10:180];

% Sets the correct location and number of ticks
set(c, 'ytick', ticks / max(ticks));

% Set the tick labels as desired
set(c, 'yticklabel', ticks);
like image 118
zelanix Avatar answered Sep 27 '22 22:09

zelanix