scatter Plot , conditional color variation based on a third value
조회 수: 6 (최근 30일)
이전 댓글 표시
I am having difficulty changing the colors in scatter plot if the condition is based on a 3rd value. For example;
f_tot = rand(3,20);
rows = 3;
x = rand(3,20);
y = rand(3,20);
hold on
box on
for p = 1: 1:rows
if f_tot >= 0.8
c = 'red';
else
c = 'blue';
end
scatter(x(:,p),y(:,p),2,c);
end
f_tot decision seems to be completely ignored when executing the condition
댓글 수: 4
Nitika Kandhari
2018년 6월 26일
Hi, If instead of just 2 colors- red and blue; I need a gradient between blue and red, how would I do that??
I am doing this:
t = 1:3580; %%Time length on the x-axis
for i = 1:1803
if z(i,t) > 0.25
scatter(t, inv(i,t), [], z(i,t), 'filled') %%Plot inverse velocity (inv- 1803*3580 matrix) against time for all data points and color them according to values in the z-matrix (1803*3580)
hold on
end
end
colormap(jet)
If I do no give the if command, my plot looks like the file attached. Essentially, I want to filter out the data points with lower values in z-matrix (blue points). Only the data points having values higher than 0.25 need to be there in the plot. Any ideas??
Nitika Kandhari
2018년 6월 27일
I got the answer and I am writing it here in case anyone else needs to do the same.
z(z <= 0.25) = nan;
This replaces the values lower than 0.25 and takes out the noise (blue dots) and filters the data.
답변 (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!