Special markers in plot within range

조회 수: 2 (최근 30일)
johnscape
johnscape 2017년 3월 4일
답변: Star Strider 2017년 3월 4일
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?

답변 (2개)

Image Analyst
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);

Star Strider
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.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by