在 MATLAB 中显示多个颜色图的颜色条

Display colorbars for multiple colormaps in MATLAB

我有一张图像想在 MATLAB 中显示并覆盖一些数据(一个单独的图像)。我为这两个图像使用了两个不同的颜色图,但似乎无法获得两个颜色条。包含两个地图的颜色条也可以。到目前为止,这是我的代码:

close all; clc;

figure(1)
im1 = ind2rgb( gray2ind(mat2gray(f,[.1 1]),256), spring(256));
h1  = imshow(  im1, [.1 1] );

hold on; 

colorbar 

FA(isnan(FA))  = 0;
alpha          = ones( size(f) );
alpha(mapvis)  = 0;
im2            = ind2rgb( gray2ind(mat2gray(FA,[0 1]),256), bone(256));
h2             = imshow(  im2, [0 1] );
set(h2, 'AlphaData', alpha);

colorbar
hold off

%cdata1 = h1.CData;
%cdata2 = h2.CData;
%cc = [cdata1; cdata2];

(我在尝试连接颜色图时加入了一些评论,不幸的是遵循了这个例子:https://se.mathworks.com/matlabcentral/answers/101346-how-do-i-use-multiple-colormaps-in-a-single-figure#Example_1) 结果如下图: 这不是我想要的。

这是在单个图形上使用多个颜色图的一种方法。这个想法是将多个 Axes 对象叠加在一起,使 Axes 背景透明,以便它们的图相互叠加。这仅适用于 2D 视图。在 3D 视图中,plots/surfaces 会错误地相互重叠。

clear all;
close all;
clc;

ax = gca;
ax(2) = copyobj(ax, ax.Parent);
linkprop(ax, {'XLim', 'YLim', 'ZLim', 'Position', 'View'});

[x, y, z] = peaks;

% plot onto first axes
pcolor(ax(1), x, y, z);
shading(ax(1), 'interp')

% plot onto second axes, arbitrarily shifting the data to a new range
contour(ax(2), x, y, -z+10, 10);

% set the colormap and CLims of each axes
set(ax(1), 'CLim', [-10, 10], 'Colormap', parula);
set(ax(2), 'CLim', [0, 20], 'Colormap', bone);

% Make the second axes invisible
set(ax(2), 'Color', 'None', 'XColor', 'none', 'YColor', 'none', 'ZColor', 'none');

% make the colorbars
cb(1) = colorbar(ax(1), 'East');
cb(2) = colorbar(ax(2), 'South');

您必须根据需要手动调整颜色栏和轴位置。