Effacer les filtres
Effacer les filtres

how to set colormap minimum and maximum for imagesc in tiledlayout

27 vues (au cours des 30 derniers jours)
RG
RG le 26 Mai 2023
Modifié(e) : Adam Danz le 26 Mai 2023
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.

Réponses (1)

Dave B
Dave B le 26 Mai 2023
Modifié(e) : Dave B le 26 Mai 2023
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 commentaire
RG
RG le 26 Mai 2023
Awesome thanks. I used the nexttile(n) option, tried set(gca), also worked.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by