Colormap generated using the information of different arrays
4 views (last 30 days)
Show older comments
Hello everyone
I am trying to plot the data in five different matrices in the same graphic. Interestingly, the elements of these matrices are not equal to NaN just in the spatial domain where, each of them, should exists. In principle, if the matrix element (i,j) of one of these matrices is different from NaN, it would not be again non-NaN in the other data arrays at (i,j). The five different matrices can be found here.
I would like to make the NaN elements to be completely transparent. As you can see, I am attaching a colormap, "Colors.txt", which is not white at the middle. I do not know if that makes any difference.
I am plotting the system as follows:
p1=uimagesc(Space_a,Space_b,mz_Tetra_1_Data);
set(p1,'alphadata',~isnan(mz_Tetra_1_Data));
hold on
p2=uimagesc(Space_a,Space_b,mz_Tetra_2_Data);
set(p2,'alphadata',~isnan(mz_Tetra_2_Data));
p3=uimagesc(Space_a,Space_b,mz_Penta_1_Data);
set(p3,'alphadata',~isnan(mz_Penta_1_Data));
p4=uimagesc(Space_a,Space_b,mz_Penta_2_Data);
set(p4,'alphadata',~isnan(mz_Penta_2_Data));
p5=uimagesc(Space_a,Space_b,mz_Hexa_Data);
set(p5,'alphadata',~isnan(mz_Hexa_Data));
colormap(Colors);
clim([-1 1]);
Is the code above correct for my purpose?
0 Comments
Accepted Answer
Mathieu NOE
on 26 Sep 2024
hello Richard again
you were pretty close to the solution , but to actually make the transparency work you should replace this line : set(p1,'alphadata',~isnan(mz_Tetra_1_Data));
with :
set(p1, 'AlphaData', ~isnan(p1.CData))
same logic on the other calls
NB it has nothing to do with what colormap you're using.
result :
code :
% read colormap colors from the text file
Colors = readmatrix('Colors.txt');
Space_a = readmatrix('Space_a.txt');
Space_b = readmatrix('Space_b.txt');
mz_Tetra_1_Data = readmatrix('mz_Tetra_1_Data.txt');
mz_Tetra_2_Data = readmatrix('mz_Tetra_2_Data.txt');
mz_Penta_1_Data = readmatrix('mz_Penta_1_Data.txt');
mz_Penta_2_Data = readmatrix('mz_Penta_2_Data.txt');
mz_Hexa_Data = readmatrix('mz_Hexa_Data.txt');
p1=uimagesc(Space_a,Space_b,mz_Tetra_1_Data);
set(p1, 'AlphaData', ~isnan(p1.CData))
hold on
p2=uimagesc(Space_a,Space_b,mz_Tetra_2_Data);
set(p2,'AlphaData',~isnan(p2.CData));
p3=uimagesc(Space_a,Space_b,mz_Penta_1_Data);
set(p3,'AlphaData',~isnan(p3.CData));
p4=uimagesc(Space_a,Space_b,mz_Penta_2_Data);
set(p4,'AlphaData',~isnan(p4.CData));
p5=uimagesc(Space_a,Space_b,mz_Hexa_Data);
set(p5,'AlphaData',~isnan(p5.CData));
colormap(Colors);
clim([-1 1]);
3 Comments
Mathieu NOE
on 26 Sep 2024
Got it - and no it has nothing to do with transparency
As I ran my code only on my PC and as I have an older release (R2020b) , the last line with clim (clim([-1 1]); ) throw an error (did not even see that in first place as the plot showed up) and this was not executed so by default my rendering was "auto scaled"
in my code if I used caxis (instead of the newer clim) with the same limits (-1 1) I got exactly the same pale rendering as you :
so try your code either removing this line or better adjust the min / max limits., see for example how we did in your other post (and use symmetrical limits and colormap if you want again white matching zero)
Mathieu NOE
on 26 Sep 2024
maybe you can replace the last line with this (does it solves your issue ? ) :
my new result (with caxis on my side) :
zm1 = max(abs(mz_Tetra_1_Data),[],'all');
zm2 = max(abs(mz_Tetra_2_Data),[],'all');
zm3 = max(abs(mz_Penta_1_Data),[],'all');
zm4 = max(abs(mz_Penta_2_Data),[],'all');
zm5 = max(abs(mz_Hexa_Data),[],'all');
zm = max([zm1;zm2;zm3;zm4;zm5]);
clim([-zm zm]); % force colors to be used symmetricaly so white correspond to zero
More Answers (0)
See Also
Categories
Find more on Colormaps 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!