[2017/03/24] Matlab绘图 - 多子图共用同一colorbar显示

师兄画的图就是好看吼> - > 

有种毕设要做不完的感觉=-= 我很少会有什么东西做不完的感觉……这种压力感 真是久违啊。


重新回归Matlab,重新设置了一下背景和字体,倒也没那么不顺眼,马马虎虎也可以欺骗自己那是Clion和Pycharm……

好了废话不多说,进入正题。


查了很久,没看到 用 subplot方法可以让 多个子图共用一个colorbar,最后在图上也只显示一个colorbar的做法。

于是用axes做之。以下是个demo


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



效果如下:



因为懒我没有采用不同的矩阵用于对比,所以看不出来是不是用了同一个colorbar标尺,当然实际上它们用的是一个标尺,因为在上面的

imagesc(f, clim);
中用的是同一个clim


恩我还是上传一张真正的效果图,如下:



好的我继续苦逼地忙碌毕设。。之后应该也会有些东西要记录下来,比如我的DNN(手动微笑)。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值