【发布时间】:2016-03-16 11:15:32
【问题描述】:
我的矩阵包含离散值 1、2 和 3,(在这种情况下)是 red、green 和 blue 的代码。颜色条在我最初没想到它们的位置显示这些标签。我想这与分配颜色的方式有关(例如,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