Adding a marker to Data Marker to Heatmap (via imagesc)
10 views (last 30 days)
Show older comments
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 Comments
Adam
on 21 Feb 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.
Accepted Answer
Adam
on 28 Feb 2019
Edited: Adam
on 28 Feb 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 Comments
Adam
on 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.
More Answers (2)
Krishna Zanwar
on 27 Feb 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 Comments
Krishna Zanwar
on 28 Feb 2019
Hey Jason,
As a work around you can remove the colorbar from the previos image and it will work.
Walter Roberson
on 28 Feb 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.
0 Comments
See Also
Categories
Find more on Data Distribution Plots 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!