在MATLAB中显示多个颜色图的颜色条 [英] Display colorbars for multiple colormaps in MATLAB

查看:88
本文介绍了在MATLAB中显示多个颜色图的颜色条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an image that I want to display in MATLAB and overlay some data (a separate image). I am using two different colormaps for these two images, but can't seem to get two colorbars. A colorbar that contains both maps would also be okay. This is my code so far:

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];

(通过尝试不带运气的以下示例,我尝试合并彩色图时加入了一些评论:这不是我想要的.

(I included some comments as i tried to concatenate the colormaps, by following this example without luck: https://se.mathworks.com/matlabcentral/answers/101346-how-do-i-use-multiple-colormaps-in-a-single-figure#Example_1) which results in the following plot: Which isn't quite what i am looking for.

推荐答案

这是在单个图形上具有多个颜色图的一种方法.这个想法是将多个Axes对象彼此叠加,使Axes背景透明,以便它们的图相互叠加.这仅适用于2D视图.在3D视图中,图/面将彼此不正确地重叠.

Here's one way to have multiple colormaps on a single figure. The idea is to overlay multiple Axes objects on top of each other, make the Axes background transparent so their plots overlay each other. This only works well for 2D view. In 3D view, plots/surfaces will overlap each other incorrectly.

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

您将必须根据需要手动调整彩条"和轴位置".

You will have to manually adjust the Colorbar and Axes Positions as you see fit.

这篇关于在MATLAB中显示多个颜色图的颜色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆