필터 지우기
필터 지우기

Plotting hitmap with different box size

조회 수: 4 (최근 30일)
Mudasser Seraj
Mudasser Seraj 2018년 7월 27일
댓글: Mudasser Seraj 2018년 7월 30일
Hello,
I have a 64x9 matrix and I want to plot a heatmap with different box sizes. Figure as below.
Can someone please help me with this? Added sample data file
  댓글 수: 5
Mudasser Seraj
Mudasser Seraj 2018년 7월 27일
편집: Mudasser Seraj 2018년 7월 27일
Yeah. That's why I am asking help if someone can do this with codes. I couldn't find anything like this in File Exchange.
jonas
jonas 2018년 7월 27일
You can do this quite easily with scatter3. I'll give it a try.

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

채택된 답변

Kelly Kearney
Kelly Kearney 2018년 7월 27일
You can create this pretty easily using patches:
The test data:
c = rand(20,9)*2 - 1; % Color value
s = c; % Scale value
Plot
% Coordinates for a box
xbox = [-1 -1 1 1 -1]*0.5;
ybox = [-1 1 1 -1 -1]*0.5;
% Coordinates for the box centers
[yc,xc] = ndgrid(1:size(c,1), 1:size(c,2));
xc = xc + 0.5;
yc = yc + 0.5;
% Scale the box and add to center coordinates
x = xc(:) + xbox.*s(:);
y = yc(:) + ybox.*s(:);
% Plot
patch(x',y',c(:),'edgecolor', 'none');
axis tight equal;
set(gca, 'clim', [-1 1]);
colorbar;
Note that in this example I'm using the implicit expansion that was introduced recently (R2017 or so)... in older versions you'll have to use repmat, bsxfun, etc.

추가 답변 (1개)

jonas
jonas 2018년 7월 27일
편집: jonas 2018년 7월 27일
Here's an alternative using scatter3.
%%Some data
[X,Y]=meshgrid(1:10,1:10);
Z=rand(10,10).*2-1;
figure;hold on
%%Scale for color
zc=(Z+1).*100;
cn = ceil(max(zc(:)));
cm = colormap(parula(cn));
%%Scale Z for box size
zb=abs(Z(:).*850);
%%plot and fix visuals
h=scatter3(X(:), Y(:), Z(:), zb,cm(ceil(zc),:),'s','filled')
colorbar
caxis([-1 1])
set(h,'markeredgecolor','k')
set(gca,'xtick',1:10,'ytick',1:10)
box on
axis([0,11,0,11])
view(2)
grid on
See attachment

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by