如何为6个子图(Matlab)实现相同的colorbar缩放?

时间:2018-05-14 15:49:45

标签: matlab plot matlab-figure colorbar

我定义了以下六个矩阵,我制作了等值线图:

% Define Matrices

Matrix1 = [2.7 -0.42 -2.22 -4.74 -9.47 159 0 0 0 0;...
-0.006 -1.21 -3.22 -6.18 188.32 147 0 0 0 0;...
0.26 -1.05 -3.43 -7.09 174.28 131 0 0 0 0;...
1.17 0.31 202.88 183.32 158.92 0 0 0 0 0;...
200 195.37 183.58 166.97 144.47 0 0 0 0 0;...
180 176.34 167.48 153.06 130 0 0 0 0 0;...
162.65 160.51 153.57 140.44 118.18 0 0 0 0 0;...
147.65 146.98 141.55 129.76 106.38 0 0 0 0 0;...
134.88 135.6 130.96 120 96.13 0 0 0 0 0;...
123.52 125.77 121.31 112 0 0 0 0 0 0];

Matrix2 = [4 -0.99 -1.42 -0.33 1.44 187 0 0 0 0;...
-0.006 -0.9 -1.21 -0.27 201.74 181 0 0 0 0;...
0.26 0.05 0 0.84 190.24 0 0 0 0 0;...
0.53 1.02 206.64 192.93 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0];

Matrix3 = [3 5.4 9.26 11.06 8.27 -378 -503 -372 0 0;...
4.72 6.63 9.01 9.66 5.92 -387 -502 -372 0 0;...
6.61 9.48 10.65 9.54 3.19 -404 -410 0 0 0;...
8.53 12.05 12.71 10.7 1.44 -452 -524 0 0 0;...
9.75 14.02 14.9 11.46 0.41 -452 0 0 0 0;...
11.49 16.38 17.07 13.26 133.7 0 0 0 0 0;...
13.38 159.22 155.57 144.49 119.4 0 0 0 0 0;...
141.92 145.5 143.29 133.37 105.08 0 0 0 0 0;...
129.5 134.26 132.01 123 90.62 0 0 0 0 0;...
118.52 123.99 123.31 114.8 0 0 0 0 0 0];

Matrix4 = [3 4.27 6.75 7.89 7.63 7.84 8.29 9.14 127.59 115.07;...
2.63 4.18 5.97 7.06 7.8 7.63 8.47 8.66 125.6 113.44;...
2.2 3.68 5.32 6.23 7.23 7.53 7.98 134.6 122.03 0;...
1.9 2.72 4.08 5.79 6.59 7.24 7.89 128.33 116.66 0;...
0.69 2.337 3.36 4.54 5.78 6.47 131.8 120.86 0 0;...
1.45 2.54 2.99 4.82 140.65 131 0 0 0 0;...
0.77 142.41 138.94 133.44 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0];


Matrix5 = [-2.1 -3.12 -13.34 -319 -421 -394 -520 0 0 0;...
-3.1 -8.34 -22.63 -347 -441 -402 -519 0 0 0;...
-6.14 -16.61 -40 -389 -470 -419 0 0 0 0;...
-7.8 -25.64 -68 -437 -506 -442 0 0 0 0;...
-8.3 -31 -98 -488 -545 0 0 0 0 0;...
-8.04 -34.15 -133 0 0 0 0 0 0 0;...
155.71 123 -403 0 0 0 0 0 0 0;...
142.92 107.42 -466.85 0 0 0 0 0 0 0;...
130 4.96 0 0 0 0 0 0 0 0;...
120.71 0 0 0 0 0 0 0 0 0];

Matrix6 = [-360 -246 -229.72 -319 -421 -394 -520 0 0 0;...
-6.95 -20 -269 -347 -441 -402 -519 0 0 0;...
-6.61 -23 -326 -389 -470 -419 0 0 0 0;...
-3.7 -15.73 -58 -437 -506 -442 0 0 0 0;...
-1.63 -6.79 -16 -114 -545 0 0 0 0 0;...
-0.28 -1.45 -4.29 151 135.5 118 96.2 0 0 0;...
163.7 160.4 155.09 148 139.89 129.86 112.75 88.91 68.28 0;...
0 0 143.34 138.28 132.21 125.62 118.46 110.49 100.79 63.28;...
0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0];

然后我在下面画出

% Interpolate for smoother contour plot

x = linspace(1,10,10);
y = linspace(1,10,10);

[xrow,ycol] = meshgrid(x,y);

newpoints = 100;
[xq,yq] = meshgrid(...
        linspace(min(min(xrow,[],2)),max(max(xrow,[],2)),newpoints ),...
        linspace(min(min(ycol,[],1)),max(max(ycol,[],1)),newpoints )...
      );

% Figures 

figure;
subplot(3,2,1)
Matrix1Interp = interp2(xrow,ycol,Matrix1,xq,yq,'cubic');
[c1,h1] = contourf(xq,yq,Matrix1Interp,100);
set(h1, 'edgecolor','none');
axis square

subplot(3,2,2)
Matrix2Interp = interp2(xrow,ycol,Matrix2,xq,yq,'cubic');
[c2,h2] = contourf(xq,yq,Matrix2Interp,100);
set(h2, 'edgecolor','none');
axis square

subplot(3,2,3)
Matrix3Interp = interp2(xrow,ycol,Matrix3,xq,yq,'cubic');
[c3,h3] = contourf(xq,yq,Matrix3Interp,100);
set(h3, 'edgecolor','none');
axis square

subplot(3,2,4)
Matrix4Interp = interp2(xrow,ycol,Matrix4,xq,yq,'cubic');
[c4,h4] = contourf(xq,yq,Matrix4Interp,100);
set(h4, 'edgecolor','none');
axis square


subplot(3,2,5)
Matrix5Interp = interp2(xrow,ycol,Matrix5,xq,yq,'cubic');
[c5,h5] = contourf(xq,yq,Matrix5Interp,100);
set(h5, 'edgecolor','none');
axis square

subplot(3,2,6)
Matrix6Interp = interp2(xrow,ycol,Matrix6,xq,yq,'cubic');
[c6,h6] = contourf(xq,yq,Matrix6Interp,100);
set(h6, 'edgecolor','none');
axis square

ax = subplot(3, 2, 6);
pos = get(ax, 'Position');

c = colorbar('Location', 'SouthOutside', 'Position', [0.1243 0.03316  0.785 0.03269]);

虽然颜色条和一切都在正确的位置,但是等高线图的比例与颜色条不匹配(我假设它与最终的矩阵图相关联)。我怎样才能使各个等高线图的比例匹配?

1 个答案:

答案 0 :(得分:2)

我会抛弃$dir = scandir($path); $min = 20; $max = 40; $type = "jpg"; $output = array_filter($dir, function ($filename) use ($min, $max, $type) { $file = pathinfo($filename); return ( $file['filename'] >= $min && $file['filename'] <= $max && $file['extension'] = "jpg"); }); ,因为你还没有显示轮廓线,而是使用imagesc。在这里,您不需要选择多个等高线,并且您也可以轻松地改变颜色范围。

您的代码如下所示:

contourf