首页 文章

如何手动设置颜色栏中的范围?

提问于
浏览
6

我有各种各样的值,当绘制为散射(x,y,z)时,显示z轴的颜色条显示了大范围的值,现在我对较低的范围值不感兴趣 . 有没有方法可以改变颜色条的范围 . 我有以下部分代码来绘制,我也打算绘制日志图 . 例如 . 我想将日志图中的范围设置为14到最大值 .

我想要一些值根本不显示 . 这样颜色条的范围就有限,比如从14到最大 . 目前它在对数图中显示从9到最大值 .

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)');

3 回答

  • 11

    这个怎么样?

    % 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

    我相信 caxis 是你正在寻找的命令 . 用法:

    caxis([minValue maxValue])
    

    像这样使用 caxis[minValue maxValue] 范围之外的所有值将分别用色图中的最低或最高值着色 .

    由于 colorbar 和朋友使用 colormap ,如果要调整使用的颜色数量,则必须调整当前的色彩映射 . 这样做:

    %# 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);
    

    当然,将其与 caxis 相结合是最强大的 .

    如果你不是 colorbarcaxis 的工作,那么's up to you -- you'll必须调整绘制的数据,以便你不想绘制的所有值都是 NaN . 这样做将使Matlab明白您不想绘制这些数据:

    data( indices_to_data_not_to_plot )  = NaN;
    surf(x,y,data);  %# or whatever you're using
    
  • 0

    试试这个:

    cmap = colormap; % get current colormap
    cmap=cmap([min max],:); % set your range here
    colormap(cmap); % apply new colormap
    colorbar();
    

相关问题