How to make color axis ticklabes with two end limits ([cmin cmax]) only?

55 ビュー (過去 30 日間)
Anil
Anil 2025 年 2 月 3 日 8:56
編集済み: Walter Roberson 2025 年 2 月 8 日 6:22
Suppose, I have subplots of 4 times 3 or higher and I cant change clim of each plot using property inspector. I tried
clim([cmin cmax])
but that shows a full range instead of two ticklabels (with auto ticks) only. is there a way to fix two end limits with ticklabes on the color axis. Thanks.
Edited:syntax for ticklabes (not ticks) as cmin and cmax .
  2 件のコメント
Mathieu NOE
Mathieu NOE 2025 年 2 月 3 日 9:08
I am not sure to understand how the result should look like
you want only two colors to be displayed ?
Anil
Anil 2025 年 2 月 4 日 0:06
@Mathieu NOE I want limit on color axis as min and max only (just two axis label) as i can set lables by property inspector. I amlloking for a syntax for that.

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

回答 (1 件)

Star Strider
Star Strider 2025 年 2 月 3 日 11:58
One problem may be that your clim call (at least as posted) needs parentheses.
This call to clim:
cl = clim;
should return the limits as a 2-element vector.
If you want to set them, use:
clim([-5 5])
or some such, depending on what you want.
.
  11 件のコメント
Anil
Anil 2025 年 2 月 5 日 0:02
編集済み: Walter Roberson 2025 年 2 月 8 日 6:22
@Star Strider, @Walter Roberson Thank you very much for your help and suggetions. here is the answer of the support team
clear,clc,close all
% Sample data for demonstration
data = rand(10, 10, 12); % 12 subplots with random data
% Define color limits
cmin = 0;
cmax = 1;
% Create a 4x3 subplot layout
figure;
for i = 1:12
subplot(4, 3, i);
imagesc(data(:, :, i)); % Display data
caxis([cmin cmax]); % Set color limits
colormap('jet'); % Choose colormap
% Add colorbar and customize
hcb = colorbar;
hcb.Ticks = [cmin, cmax];
hcb.TickLabels = {num2str(cmin), num2str(cmax)};
title(['Plot ', num2str(i)]);
end
Star Strider
Star Strider 2025 年 2 月 5 日 1:49
Interesting.
I wasn’t aware of the context.

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

カテゴリ

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

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by