How to I plot a vector whose points change in color based on the value of another vector?
19 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Ashutosh Singh Baghel
2021 年 9 月 20 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!