how to plot a scattered heat map
Afficher commentaires plus anciens
Hi,
I have 2 vectors from a table, and I'd like to create chart similar to the one in the picture. I didn't found any matlab of the shelf command for it, is there is a way that I can 

3 commentaires
Mohammad Sami
le 29 Jan 2020
Something like this perhaps ?
https://www.mathworks.com/matlabcentral/answers/89665-generating-an-array-of-hexagonal-shape-pattern
sani
le 29 Jan 2020
Mohammad Sami
le 29 Jan 2020
Modifié(e) : Mohammad Sami
le 29 Jan 2020
Yes the scatter function will work for that.
scatter(x,y,size,color).
If you don't have size you can leave it empty.
scatter(x,y,[],color).
Use colormap to change the coloring scheme if you need to.
Réponses (1)
Image Analyst
le 29 Jan 2020
Mohammad is right. Make a colormap, such as jet or hsv, and build a color table where for each value of your data, you assign the corresponding color from the colormap. Easy. Attach your data if you can't do it and someone will for you. Something like this untested code:
cmap = jet(256);
v = rescale(yourValues, 1, 256); % Nifty trick!
numValues = length(yourValues)
markerColors = zeros(numValues, 3)
% Now assign marker colors according to the value of the data.
for k = 1 : numValues
row = round(v(k));
markerColors(k, :) = cmap(row, :);
end
% Create the scatter plot.
scatter(x, y, [], markerColors);
grid on;
4 commentaires
Charlie Hillary
le 3 Déc 2020
Hi! Could you specify what yourValues and numValues are?
I have a 3 column matrix with the third being the colour value like so:
Where
dat = [0 21 1.07 ;
0 60 0.51 ;
0 81 0.74 ;
0 102 0.84 ;
0 151 0.96 ;
0 201 1.26 ;
0 300 1.08 ;
0 387 1.31 ;
0 501 1.44 ;
0 589 1.4 ;
0 693 1.39 ;
0 792 1.25 ;
0 889 1.16 ;
0 990 1.07 ;
0 1185 1.21 ;
0 1384 1.14 ;
0 1582 1.44 ;
0 1778 1.42 ;
0 1976 0.69 ;
0 2466 1.04 ;
0 2957 1.64 ;
0 3201 0.94 ;
0 3521 0.82 ;
48.8 19 1.01 ;
48.8 37 0.37 ;
48.8 50 0.47 ;
48.8 75 0.63 ;
48.8 99 0.75 ;
48.8 119 0.57 ;
48.8 137 3.04 ;
74.8 21 0.73 ;
74.8 39 0.34 ;
74.8 71 0.52 ;
74.8 149 0.6 ];
How would I adapt this:
cmap = jet(256);
v = rescale(myVal, 1, 256); % Nifty trick!
numValues = length(myVal)
markerColors = zeros(numVal, 3)
% Now assign marker colors according to the value of the data.
for k = 1 : numVal
row = round(v(k));
markerColors(k, :) = cmap(row, :);
end
% Create the scatter plot.
scatter(x, y, [], markerColors);
grid on;
To work with my data?
Charlie
Image Analyst
le 3 Déc 2020
What does dat represent? A colormap? Or (x,y,z) spatial coordinates?
Wen Chuan Chong
le 30 Jan 2021
Hi!
I have 4 variables (x,y,z,energy) and I would like the colour to be on the energy variable. Can you advise on how I would achieve this?
Best regards,
Jacob
Image Analyst
le 30 Jan 2021
@Wen Chuan Chong, can you attach your 4 variables in a .mat file in a new question?
save('answers.mat', 'x', 'y', 'z', 'energy');
That way we'll have something to work with. In the meantime, see my attached example.

Catégories
En savoir plus sur Color and Styling dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!