how to set colormap minimum and maximum for imagesc in tiledlayout
37 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Dave B
on 26 May 2023
Edited: Dave B
on 26 May 2023
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';
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!