师兄画的图就是好看吼> - >
有种毕设要做不完的感觉=-= 我很少会有什么东西做不完的感觉……这种压力感 真是久违啊。
重新回归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(手动微笑)。