how to set the range in the colorbar manually?

前端 未结 3 1451
不知归路
不知归路 2020-12-06 13:39

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 rang

相关标签:
3条回答
  • 2020-12-06 14:14

    Try this:

    cmap = colormap; % get current colormap
    cmap=cmap([min max],:); % set your range here
    colormap(cmap); % apply new colormap
    colorbar();
    
    0 讨论(0)
  • 2020-12-06 14:22

    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
    
    0 讨论(0)
  • 2020-12-06 14:22

    How about this?

    % don’t know why, but apparently your x and y are one value too long?
    x = x(1:end-1); y = y(1:end-1); 
    
    % only plot values of 14 or higher
    scatter(x(gnd>=14), y(gnd>=14), 5, gnd(gnd>=14);
    
    0 讨论(0)
提交回复
热议问题