Adding a marker to Data Marker to Heatmap (via imagesc)

10 vues (au cours des 30 derniers jours)
Jason
Jason le 21 Fév 2019
Commenté : Jason le 4 Mar 2019
Hello, i have a matrix Ib
2.29 2.29 2.29 2.29 1.89 1.89 1.89 1.89 1.77
2.29 2.29 2.29 2.29 1.89 1.89 1.89 1.89 1.77
1.77 1.77 1.77 1.77 1.89 1.89 1.89 1.89 0
1.77 1.77 1.77 1.77 1.89 1.89 1.89 1.89 0
2.81 2.81 2.81 2.81 1.89 1.89 1.89 1.89 0
2.81 2.81 2.81 2.81 1.89 1.89 1.89 1.89 0
0 0 0 0 2.50 2.50 2.50 2.50 0
I want to view as a heat map, so use imagesc to do this:
subplot(7,6,[22,23,24]);
imagesc(Ib2); colorbar; title('Std Background el','FontSize',8)
axis off
This gives me:
I want to be able to highlight any zeros visually and so wanted to either colour that data with a green colour, or if thats too difficuly just plot a green cross superimposed.
I have tried this:
[row,col]=find(Ib==0)
subplot(7,6,[22,23,24]); hold on;
plot(col,row,'gx')
But this just creates a new plot over the top.
Any suggestions please.
Thanks
Jason
  2 commentaires
Adam
Adam le 21 Fév 2019
Where are you defining the colourmap since hot is not the default colourmap? It looks, from the colourbar, to be a very coarse colourmap of maybe just 10 points?
You can edit a colourmap, such as hot, if you wish as e.g.
mycmap = hot( 10 );
mycmap( 1,: ) = [0 1 0];
colourmap( hAxes, mycmap );
where hAxes is the handle of the axes you want to apply it to.
Jason
Jason le 22 Fév 2019
Hi Adam. my values will range from zero to 4095. if i wanted to keep the course settings (10) but only wanted the value of zero to be green rather than the 1st range how could this be done. at the moment , the 1st color bin would be 0-40 ish right? i only want zero to be green.
thanks

Connectez-vous pour commenter.

Réponse acceptée

Adam
Adam le 28 Fév 2019
Modifié(e) : Adam le 28 Fév 2019
I guess you could take the odd approach of making the axes green (when you plot an image the axes should be entirely hidden so their colour is irrelevant) and then use AlphaData on your image to make the 0s transparent.
e.g.
hImage = imagesc( Ib2, 'AlphaData', Ib2 )
should work in this case, with e.g.
hAxes.Color = 'g';
where hAxes is your axes handle, which you can get as the returned argument from a call to subplot if you wish.
As an example:
figure; hAxes = gca;
imagesc( hAxes, magic( 25 ), 'AlphaData', magic( 25 ) > 30 );
hAxes.Color = 'g';
For you, as mentioned, it should be simpler though as your data should be its own mask if it is just 0s you want to make green. In my example I just used 'magic' as I often do as a quick way to create some image, but it does not include any 0s so I had to create a mask of all values > 30 instead.
Note though that it is important to set axes colour after the imagesc as imagesc is one of those functions that also resets various axes properties, including the colour.
  3 commentaires
Adam
Adam le 4 Mar 2019
You need the mask the other way round - i.e.
Nse > 1
because 1 in the mask is opaque data and 0 is transparent. In your case you made all data < 1 opaque.
Didn't you say you wanted only exactly 0s to be green though originally? If so than simply using Nse as your mask would work, though in the data you give here you have no 0s anyway.
Jason
Jason le 4 Mar 2019
Perfect, thankyou.
I may need to choose the level, for now I have chosem it to be 1.
Thnaks again

Connectez-vous pour commenter.

Plus de réponses (2)

Krishna Zanwar
Krishna Zanwar le 27 Fév 2019
Hey Jason,
The second subplot command is creating another plot over the top of your original plot. Just remove the second subplot command and your code should work fine.
  2 commentaires
Jason
Jason le 27 Fév 2019
Hi Krishna, thanks for your help. But I use hold on.
I also do some plotting on other subplots and then comeback to the on I need after some calculations so need to identify the actual subplot.
Jason
Krishna Zanwar
Krishna Zanwar le 28 Fév 2019
Hey Jason,
As a work around you can remove the colorbar from the previos image and it will work.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 28 Fév 2019
temp = hot(10);
cmap = repelem(temp, 409, 1);
cmap(1,:) = [0 1 0];
colormap(cmap)
This is not exactly correct as it creates a 4090 entry colormap instead of 4096.

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by