Effacer les filtres
Effacer les filtres

How to plot scatter graph with colourmap functon

1 vue (au cours des 30 derniers jours)
Charlie Hillary
Charlie Hillary le 3 Déc 2020
Commenté : Ameer Hamza le 3 Déc 2020
Hi,
I have this 3 column matrix, where:
column 1 = x values
column 2 = y values
columnn 3 = value of each given point
myVal = [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 ;
74.8 200 0.89 ;
74.8 300 0.56 ;
74.8 398 0.74 ;
74.8 496 0.81 ;
74.8 596 0.86 ;
74.8 694 1.03 ;
74.8 792 0.85 ;
282.7 15 0.12 ;
282.7 54 0.19 ;
282.7 80 0.18 ;
282.7 100 0.24 ;
282.7 199 0.29 ;
282.7 497 0.56 ;
282.7 695 0.76 ];
How would I adapt this data to work for this scatter heatmap function:
cmap = jet(256); %state colourmaop
v = rescale(myVal, 1, 256);
numVal = 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;
Charlie
  3 commentaires
Charlie Hillary
Charlie Hillary le 3 Déc 2020
Ok. I get this error 'Index in position 2 exceeds array bounds (must not exceed 2).'. How so? as the value is 3
Charlie Hillary
Charlie Hillary le 3 Déc 2020
Got it working dont worry

Connectez-vous pour commenter.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 3 Déc 2020
Try this
x = myVal(:,1);
y = myVal(:,2);
z = myVal(:,3);
cmap = jet(256); %state colourmaop
min_val = min(z);
max_val = max(z);
colors = interp1(linspace(min_val, max_val, 256), cmap, z);
scatter(x, y, [], colors);
  3 commentaires
Charlie Hillary
Charlie Hillary le 3 Déc 2020
Note that my actually data file is much bigger than I stated. It works for this smaller data value though
Ameer Hamza
Ameer Hamza le 3 Déc 2020
Can you explain what do you mean by "I get an error for the z value, as this value is not supposed to exceed 2". What is the error message?

Connectez-vous pour commenter.

Plus de réponses (1)

Bjorn Gustavsson
Bjorn Gustavsson le 3 Déc 2020
Modifié(e) : Bjorn Gustavsson le 3 Déc 2020
To make it short and simple couldn't you just use scatter and let it automatically scale the values?
scatter(x,y,23,myVal,'filled')
colormap(jet(256))

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by