How to edit the grid size in heatmap and how to make the color scale just a binary value?

I have a heat map as shown below. I want to make it look as continous plot as possible, or in other words I want to make it appear without individual grid borders. Also, is it possible to make a binary color seelection like red(high) and yellow(low). My data has a few inf values.Also, is there any way to remove the numbering from the x and y axis in the heatmap figure?
h = heatmap(C);
colormap cool
% h.Colormap = cool;
h.ColorScaling = 'scaled';
h.ColorLimits = [0 10000];
h.GridVisible = 'off';
h.MissingDataColor = [0.8 0.8 0.8];
h.Title = 'Phase matrixs';
h.XLabel = '';
h.YLabel = '';
% caxis(h,[0 1]);
1.jpg

 채택된 답변

Adam Danz
Adam Danz 2020년 1월 5일
편집: Adam Danz 2020년 1월 5일
"I have a heat map ... I want to make it look as continous plot as possible, ... I want to make it appear without individual grid borders."
Use imagesc(C) instead. You can smooth out the pixels using several different methods. For example, you could interpolate the values or, if you have the image processing toolbox, you can do a 2D gaussian filter as demonstracted below.
imagesc(imgaussfilt(C,2))
"is there any way to remove the numbering from the x and y axis in the heatmap figure?"
Yes, but it's much easier to do if you use imagesc() by setting the xtick and ytick values.
"Also, is it possible to make a binary color seelection like red(high) and yellow(low). "
Yes, you can change the colormap
set(gca, 'Colormap',[1 1 0; 1 0 0])

댓글 수: 4

But I am not getting this working for other images. Like if you see below.
left(heatmap) and right(filtered image).
I have attached the C matrix below.
2.JPG
% set(figure, 'Visible', 'off');
% h = heatmap(C);
h = imagesc(imgaussfilt(C,2));
% colormap cool
% h.Colormap = cool;
% h.ColorScaling = 'scaled';
% h.ColorLimits = [0 10000];
% h.GridVisible = 'off';
% h.MissingDataColor = [1 1 1];
% h.Title = 'Phase matrixs';
% h.XLabel = '';
% h.YLabel = '';
% caxis(h,[0 1]);
set(gca, 'Colormap',[1 1 0; 1 0 0])
set(gca,'xtick',[])
set(gca,'xticklabel',[])
set(gca,'ytick',[])
set(gca,'yticklabel',[])
%%
dirname_phase_matrix = fullfile(dirname,sprintf('/figure%d_2.jpg',jaycp));
saveas(h,dirname_phase_matrix) % here you save the figure
xlswrite(fullfile(dirname,sprintf('/matrix%d.xlsx',jaycp)),matrix);
xlswrite(fullfile(dirname,sprintf('/C%d.xlsx',jaycp)),C);
Here's what I get with those data and that code,
200105 211224-Figure 1.png
Yes I got it. Some weird image saving issue. Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Why not use imshow()?
C = 1000 * rand(100); % Create sample data.
C(10, 20) = inf; % Put an inf in there, like the poster has.
imshow(C, [0, 1000], 'InitialMagnification', 800); % Display the image.
colormap(cool(256)); % Apply the colormap.
handleToColorBar = colorbar % Display the colorbar.
% Turn off tick marks so that the colorbar won't have the numbers next to it.
handleToColorBar.Ticks = [];
I'm not sure what you mean by "binary color seelection like red(high) and yellow(low)". Does that mean that you only want two colors in there, not a gradient? If so, which value is the cutover value from red to yellow?

댓글 수: 3

This works good but can it be smoothened such that it looks like below (without grid borders?)
left(target) and right(yours)
3.JPG
What are you doing to get C? The matrix in the workbook has some weird pattern where some pixels are 0 and others are 65535, and the "real" data is in some pattern. Doing this got rid of some bad rows and columns:
data = xlsread('C20.xlsx');
data(:, 1:4:end) = [];
data(4:4:end, :) = [];

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 1월 5일

댓글:

2020년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by