matlab多个bar的命令如何链接,求助:Matlab两个图共用一个colorbar

上面的有问题,我在CDSN上面找到了一个博客回答这个问题。应该调用imagesc函数实现,具体如下。转载请注明:

% 作者:Moplast_Cat

% 来源:CSDN

clc, clear, close all;

top_margin = 0.03; % top margin

btm_margin = 0.03; % bottom margin

left_margin = 0.03;% left margin

right_margin = 0.15;% right margin

fig_margin = 0.08; % margin beween figures(sub)

row = 4; % rows

col = 3; % cols

% Generate some test data to show

x = 0 : 1: 6;

y = 0 : 1.5: 9;

f = y' * x;

% '54' and '0' respectively represent max(f) and min(f)

% both need to be calculated or traversed to determine

% for convenience, I directly use results

clim = [0 54];

% Calculate figure height and width according to rows and cols

fig_h = (1- top_margin - btm_margin - (row-1) * fig_margin) / row;

fig_w = (1 - left_margin - right_margin - (col-1) * fig_margin) / col;

for i = 1 : row

for j = 1 : col

% figure position: you can refer to 'help axes' to review the

% parameter meaning, note that original point is lower-left

position = [left_margin + (j-1)*(fig_margin+fig_w), ...

1- (top_margin + i * fig_h + (i-1) * fig_margin), ...

fig_w, fig_h]

axes('position', position)

% draw colorful pictures...

imagesc(f, clim);

% title, labels

title(['fig' num2str((i-1)*row+j)]);

xlabel(['row:' num2str(i)]);

ylabel(['col:' num2str(j)]);

end

end

% draw colorbar

axes('position', [1-right_margin-fig_margin, btm_margin, 0.2, 1-(top_margin+btm_margin)]);

axis off;

colorbar();caxis(clim);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值