how to set colormap minimum and maximum for imagesc in tiledlayout

25 ビュー (過去 30 日間)
RG
RG 2023 年 5 月 26 日
編集済み: Adam Danz 2023 年 5 月 26 日
Hi, there, I'm trying to switch from subplot to tiledlayout, but one thing I can't figure out,
how to use set command to set colormap limit in imagesc in the tiledlayout.
Here is a subplot example:
subplot(3,5,1), hold on;
imagesc(vertcat(x1,x2)),daspect([1 1 1]),colormap(currentcolormap),colorbar;
set(subplot(3,5,1),'CLim',[min max]);
here is the tiledlayout example:
tiledlayout(1,3);
nexttile
imagesc(vertcat(x1,x2)),daspect([1 1 1]),colormap(currentcolormap),colorbar;
set(tiledlayout(1,1),'CLim',[min max]);
the error that I get when running set Clim in tiledlayout is:
Error using matlab.graphics.layout.TiledChartLayout/set
Unrecognized property CLim for class TiledChartLayout.
Is there a substituion to that or way around?
Thanks.

回答 (1 件)

Dave B
Dave B 2023 年 5 月 26 日
編集済み: Dave B 2023 年 5 月 26 日
You can grab the Axes object, use gca, or use nexttile to refer to a location in the grid:
tiledlayout(1,3);
ax = nexttile;
imagesc(randn(5))
set(ax,'CLim', [-2 2]);
% or ax.CLim = [-2 2]
% or clim(ax, [-2 2])
colorbar
nexttile
imagesc(randn(5))
set(gca, 'CLim', [-2 2])
% or clim([-2 2])
colorbar
nexttile
imagesc(rand(5))
set(nexttile(3), 'CLim', [-2 2]) % because it's the third tile
colorbar
As a side note, a common thing folks want to do in multi-axes visualizations is set the CLim on all the Axes objects in the layout at once. Using findobj is a good way to do this (rather than the TiledChartLayout's Children property) because it makes sure that you're setting the property an the Axes and not some other object in the layout. Here I did that and also included a shared colorbar in the east tile of the layout...just for fun!
figure
tcl = tiledlayout(2,2);
for i = 1:4
nexttile
imagesc(randn(5))
end
set(findobj(tcl,'Type','Axes'), 'CLim', [-2 2])
c=colorbar;
c.Layout.Tile='east';
  1 件のコメント
RG
RG 2023 年 5 月 26 日
Awesome thanks. I used the nexttile(n) option, tried set(gca), also worked.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by