How to I plot a vector whose points change in color based on the value of another vector?
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have two 4000x1 vectors, call them A and B. I want to plot A on a graph, and I want the color to change based on the value of B. For example, if B(1) is between 0.95-1, I want to plot A(1) in dark red. If B(1) is between 0.9-0.949, I want to plot A(1) in a lighter shade of red. I want the colors to change from dark red at the max to light blue at the minimum value of B.
I initially tried this with a for loop and conditional statements (if B(i) > 0.95, scatter(x(i),A(i),1,'r'), but I want more color variation, and using the color short names doesn't provide intensity on the color. Is there a way this can be done without brute forcing it using hexadecimal color codes?
1 commentaire
Réponses (1)
Ashutosh Singh Baghel
le 20 Sep 2021
Hi Ryan, I understand you wish to use the 'scatter' function to plot 'A' and change color of data points based on value of 'B'. Please refer to the example shown below.
n = 4000;
A = 1:n;
B = rand(1,n);
r = linspace(1,0,n);
c = [r' zeros(n,2)];
scatter(A,B,[],c);
0 commentaires
Voir également
Catégories
En savoir plus sur Scatter Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!