how to set colormap minimum and maximum for imagesc in tiledlayout

조회 수: 36 (최근 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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by