scatter plot with color dependent on variable.
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I need to plot a scatter graph, where the color goes from red to blue gradually and depends on the value of variable s (polarization value). s is calculated in excel and goes from -1 to 1. I am not sure how to achieve the above.
I am trying the following code: attached.
Any help is appreciated.
2 Kommentare
Mario Malic
am 5 Aug. 2020
Bearbeitet: Mario Malic
am 5 Aug. 2020
Just a rough suggestion, see documentation on Scatter properties for your MATLAB version, option is called CData. Here's an example of how to use it.
figure(1);
hb = bar(x, y);
hb.FaceColor = 'flat'; % Not needed for scatter I think
for ii = 1 : 1 : length(Color_Vector)
hb.CData(ii,:) = Color_RGB(ii,:);
end
I am not sure how one would one go from red to blue gradually (without visiting other colors). R (1, 0, 0), B (0, 0, 1), if you start with blue as the value for -1, Value for S = 0 would be (1, 0, 1), and then for S = 1, it would be red.
If S is monotonically increasing or decreasing then you could do only linspace(-1, 1, 512), where 512 stands for possible shades between those colors (you can use less, number of s values you have), if not, you can sort them, and then reorder colors by indexes.
Antworten (1)
Steven Lord
am 5 Aug. 2020
Use the c (usually the fourth) input when you call scatter. See the "Vary Circle Color" example on the documentation page. You want to specify c as either a three column matrix of RGB triplets or a vector of indices into the colormap.
Siehe auch
Kategorien
Mehr zu Scatter Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!