How to have a common colorbar for all tiledlayout plots?
38 ビュー (過去 30 日間)
古いコメントを表示
I want to plot two arrays A and B (both having 4 rows and 8 columns) using the tiledlayout format so that both of them have a common colorbar. I tried the following code:
A=[14,8,3,5,6,5,3,3;16,2,7,-7,3,1,1,4;3,1,1,1,1,0,0,0;3,1,2,1,1,0,0,0];
B=[5,4,3,3,1,0,0,0;33,0,5,8,5,4,3,5;0,0,0,1,0,0,0,0;2,0,1,2,0,0,0,0];
figure;
t = tiledlayout(1,2,'TileSpacing','compact','Padding','compact');
nexttile;
imagesc(A);
title('A','FontWeight','bold','FontSize',12,'FontName','Helvetica');
nexttile;
imagesc(B);
title('B','FontWeight','bold','FontSize',12,'FontName','Helvetica');
cb = colorbar;cb.Layout.Tile = 'east';
Notice that the element at row=2 and column=4 of array 'A' is a negative number (-7). However, the common colorbar made by the code given above is only showing positive values as shown in the screenshot given below:
How to solve this issue so that the common colorbar shows all the range of values in both the tiles?
0 件のコメント
採用された回答
Voss
2022 年 6 月 17 日
You can calculate the min and max value of A and B together and set the CLim of both axes to those values using the clim (formerly known as caxis) function.
A=[14,8,3,5,6,5,3,3;16,2,7,-7,3,1,1,4;3,1,1,1,1,0,0,0;3,1,2,1,1,0,0,0];
B=[5,4,3,3,1,0,0,0;33,0,5,8,5,4,3,5;0,0,0,1,0,0,0,0;2,0,1,2,0,0,0,0];
c_min = min([A(:); B(:)]);
c_max = max([A(:); B(:)]);
figure;
t = tiledlayout(1,2,'TileSpacing','compact','Padding','compact');
nexttile;
imagesc(A);
clim([c_min c_max]);
title('A','FontWeight','bold','FontSize',12,'FontName','Helvetica');
nexttile;
imagesc(B);
clim([c_min c_max]);
title('B','FontWeight','bold','FontSize',12,'FontName','Helvetica');
cb = colorbar;
cb.Layout.Tile = 'east';
4 件のコメント
Voss
2022 年 11 月 21 日
Depending on what you want, you might try playing with the colorbar's Position or the axes' CLim.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Orange についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!