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!