Adding a marker to Data Marker to Heatmap (via imagesc)
16 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205244/image.png)
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 个评论
Adam
2019-2-21
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.
采纳的回答
Adam
2019-2-28
编辑:Adam
2019-2-28
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 个评论
Adam
2019-3-4
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.
更多回答(2 个)
Krishna Zanwar
2019-2-27
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 个评论
Krishna Zanwar
2019-2-28
Hey Jason,
As a work around you can remove the colorbar from the previos image and it will work.
Walter Roberson
2019-2-28
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!