how to set colormap minimum and maximum for imagesc in tiledlayout

37 次查看(过去 30 天)
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';

类别

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