Это простая, но общая задача, требуемая при попытке исправить цветную карту в соответствии с 2D-матрицей значений. Чтобы продемонстрировать рассмотрение проблемы в Matlab, решение не обязательно должно быть в Matlab (т.е. Представленный здесь код предназначен только для демонстрационной цели).
x = [0,1,2; 3,4,5; 6,7,8];
imagesc(x)
axis square
axis off
So the output is as:
x = [0,1,2; 3,4,5; 6,7,18];
which looks logical but makes problems when we wish to compare/trace elements in two maps. Since the colormap association is changed it is almost impossible to find an individual cell for comparison/trace etc.
x = [0,1,2; 3,4,5; 6,7,18];
m = 8;
x(x>=m) = m;
which works perfectly.One of the cases that this issue occurs is when we have many simulations sequentially and wish to make a sense-making animation of the progress; in this case each color should keep its association fixed.
Индексирование довольно быстро, поэтому я не думаю, что вам нужно беспокоиться.
Однако, в Matlab, вы можете передать в clims
аргумент imagesc
:
imagesc(x,[0 8]);
Это отображает все значения выше 8 в верхний цвет в цветовой шкале и все значения ниже 0 до нижнего цвета в цветовой шкале, а затем растягивает масштаб для цветов между ними.
В Python с использованием пакета MatPlotLib
решение выглядит следующим образом:
import pylab as pl
x = [[0,1,2],[3,4,5],[6,7,18]]
pl.matshow(x, vmin=0, vmax=8)
pl.axis('image')
pl.axis('off')
show()
So vmin
and vmax
are boundary limits for the full range of colormap.f1 = figure;
x = [0,1,2; 3,4,5; 6,7,8];
imagesc(x)
axis square
axis off
limits = get(gca(f1),'CLim');
f2 = figure;
z = [0,1,2; 3,4,5; 6,7,18];
imagesc(z)
axis square
axis off
caxis(limits)