Azzera filtri
Azzera filtri

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

25 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 27 Ott 2023
imagescn appears to be https://www.mathworks.com/matlabcentral/fileexchange/61293-imagescn
Francesca Pisani
Francesca Pisani il 29 Ott 2023
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.

Accedi per commentare.

Risposta accettata

Sulaymon Eshkabilov
Sulaymon Eshkabilov il 29 Ott 2023
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 Commenti
Francesca Pisani
Francesca Pisani il 30 Ott 2023
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 il 30 Ott 2023
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)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by