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 Kommentare

jonas
jonas am 27 Jul. 2018
What do the size signify?
Mudasser Seraj
Mudasser Seraj am 27 Jul. 2018
In this case, color and value signifies the same value within the range of [-1 1]. In my case, I want to signify the value of each column with heatmap, and box size will signify the value with respect to table. Fot instance, column 1 (1400-25) has the range [-111.875 -107.186] so the heat map will vary within this range. However, the each cell value will be compared with table range,which is [-111.875 605.454], to get the size of the box.
Walter Roberson
Walter Roberson am 27 Jul. 2018
Neither heatmap() or HeatMap() (from Bioinformatics toolbox) can do this for you.
You might want to look in the File Exchange to see if you can find some code to adapt.
Mudasser Seraj
Mudasser Seraj am 27 Jul. 2018
Bearbeitet: Mudasser Seraj am 27 Jul. 2018
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 am 27 Jul. 2018
You can do this quite easily with scatter3. I'll give it a try.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Kelly Kearney
Kelly Kearney am 27 Jul. 2018

1 Stimme

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.

Weitere Antworten (1)

jonas
jonas am 27 Jul. 2018
Bearbeitet: jonas am 27 Jul. 2018

0 Stimmen

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

Kategorien

Mehr zu Data Distribution Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by