Special markers in plot within range
2 次查看(过去 30 天)
显示 更早的评论
I'm working on a plot, with data on the y axis between 900 and 1100. I want the markers to be colored if they are in another range ([400, 800]) . Is it possible? If it is, then how?
0 个评论
回答(2 个)
Image Analyst
2017-3-4
Try plotting over the plot
indexes = y >= 400 & y <= 800;
% First just plot everything as blue stars with lines in between
plot(x, y, 'b*-');
% Now overplot data points in the range with a red spot.
hold on;
plot(x(indexes), y(indexes), 'r.', 'MarkerSize', 30);
0 个评论
Star Strider
2017-3-4
It is certainly possible, and likely straightforward. It would help if you are a bit clearer on what you want.
Does your plot go from 400 to 1100 on the y-scale, and you only want data in the range of 400 to 800 to have colored markers?
Is it 2D or 3D?
See if this does what you want:
x = 1:50; % Create X Data
y = randi([400 1100], 1, 50); % Create Y Data
select = (y >= 400) & (y <= 800); % Select Subset
figure(1)
plot(x(~select), y(~select), 'pk')
hold on
plot(x(select), y(select), 'pg', 'MarkerFaceColor','g')
hold off
The ‘select’ assignment is a logical vector with 1 or true corresponding to the y-values that meet the criteria, and 0 or false for the others. The tilde ‘~’ here operates as a negation operator, turning the 1 values to 0 and 0 to 1. It makes the code much easier to write.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!