How to plot scatter graph with colourmap functon

1 Ansicht (letzte 30 Tage)
Charlie Hillary
Charlie Hillary am 3 Dez. 2020
Kommentiert: Ameer Hamza am 3 Dez. 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 Kommentare
Charlie Hillary
Charlie Hillary am 3 Dez. 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 am 3 Dez. 2020
Got it working dont worry

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 3 Dez. 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 Kommentare
Charlie Hillary
Charlie Hillary am 3 Dez. 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 am 3 Dez. 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 3 Dez. 2020
Bearbeitet: Bjorn Gustavsson am 3 Dez. 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))

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by