필터 지우기
필터 지우기

How to plot a map with logarithmic colorbar and colormap with imagesc

조회 수: 25 (최근 30일)
Hello, I ask for your help since I've been trying to create maps with a logarithmic colormap and colorbar, but I haven't managed so far.
The problem is I have a loop through which I plot a number of maps using "imagescn", each map is referred to an hour of the day and represents the deposited kilograms of sediments into a lake due to a turbid input. Since the input changes a lot during the day, I want to be able to see in each plot values that range between 0 and 62 (maximum value of all times). As I'm doing now, nothing has changed and the colorbar and colormap are still linear, so that I can't see very well the smallest values . Also, I want the every plot in my loop has the same colorbar limits.
This is a part of my code: (i'm using MatlabR2021a)
for t = 10:10:200 %every t is referred to a time of the day
figure(t)
colormap('parula');
my_clim=[0 62];
c=[0 0.001 0.01 0.02 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 45 50 55 60];
data=array_data_rotated_t; %this array changes at each timestep and it is a 27x29 double array
contourf(log(data(:,:)),log(c));
colormap(parula);
caxis(log([c(1) c(length(c))]));
colorbar('FontSize',11,'YTick',log(c),'YTickLabel',c);
imagescn(array_data_rotated_t);
h=colorbar;
end
Thank you for your help!
Francesca
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 10월 27일
imagescn appears to be https://www.mathworks.com/matlabcentral/fileexchange/61293-imagescn
Francesca Pisani
Francesca Pisani 2023년 10월 29일
Thank you, I've just tried to put the first number in c as 0.001 instead of 0, but nothing changed: the colorbar limits change for each figure and the colormap is not logarithmic. Imagescn works exactly as imagesc, except for the fact that NaN values are transparent.

댓글을 달려면 로그인하십시오.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 10월 29일
for t = 10:10:200 %every t is referred to a time of the day
figure(t)
colormap('parula');
my_clim=[0 62];
c=[0 0.001 0.01 0.02 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 45 50 55 60];
data=array_data_rotated_t; %this array changes at each timestep and it is a 27x29 double array
contourf(log(data(:,:)),log(c));
colormap(parula);
caxis(log([c(1) c(length(c))]));
colorbar('FontSize',11,'YTick',log(c),'YTickLabel',c);
imagescn(array_data_rotated_t);
h=colorbar;
set(gca,'ColorScale','log') % USE this command
end
  댓글 수: 4
Francesca Pisani
Francesca Pisani 2023년 10월 30일
Thank you, but unfortunately this shows an error: Unrecognized property 'Limit' for class 'matlab.graphics.illustration.ColorBar'.
I'm also trying to get one figure made of subplots, but I don't manage. For example, I've tried changing the loop saying :
figure(1)
for t=60:1:62
fig=figure(1);
sph{t} = subplot(3,1,t,'Parent',fig);
contourf(sph{t},x,y,t.*z(:,:,t))
caxis(sph{t},[0,62]);
and keeping other lines as before. But I get the error:
Error using subplot (line 319)
Index exceeds number of subplots.
Error in Deposited_mass_map (line 46)
sph{t} = subplot(3,1,t,'Parent',fig);
Why does it happen? The number of subplots seems correct to me.
Walter Roberson
Walter Roberson 2023년 10월 30일
When you subplot(A, B, C) then C must not exceed A*B. subplot(3,1,t) then t must be 1 2 or 3 (or a vector of multiple values in that range)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by