【问题标题】:MATLAB/Octave: Adjust tick position/alignment for colorbar axisMATLAB/Octave:调整颜色条轴的刻度位置/对齐方式
【发布时间】:2016-03-16 11:15:32
【问题描述】:

我的矩阵包含离散值 123,(在这种情况下)是 redgreenblue 的代码。颜色条在我最初没想到它们的位置显示这些标签。我想这与分配颜色的方式有关(例如,2.4 不是green,而是blue),它不假定离散值。

我希望有类似“TickLabelAlignment”之类的设置,但找不到任何东西。所以我不得不“手动”调整位置,这是成功的。然而,有没有更通用的方法来做到这一点?我觉得我正在使用一种解决方法。

例子:

% set gnuplot as graphics toolkit, set custum colormap and create exemplary matrix
graphics_toolkit('gnuplot');
colormap([1 0 0; 0 1 0; 0 0 1]);
A = randi([1 3], 5, 5);

% plot with standard settings
subplot (2, 1, 1);
imagesc(A);
caxis([1 3]);
mycb = colorbar();
set(mycb, 'YTick', [1 2 3], 'YTickLabel', {'red', 'green', 'blue'});

% plot with adjusted tick positions (the way I want the colorbar to look like)
subplot (2, 1, 2);
imagesc(A);
caxis([1 3]);
mycb = colorbar();
set(mycb, 'YTick', [4/3 2 8/3], 'YTickLabel', {'red', 'green', 'blue'});

【问题讨论】:

    标签: matlab alignment octave colorbar


    【解决方案1】:

    据我所知,不支持仅支持整数数学的颜色图。您可以做的最好的事情是概括数学:

    % calculate the points where the colour segments start/end
    b = linspace(1,n,n+1);
    % calculate the centers;
    c = mean([b(1:end-1);b(2:end)]);
    

    n=3(三种颜色)计算您在上面使用的位置。

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 1970-01-01
      • 2013-02-21
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      相关资源
      最近更新 更多