Special markers in plot within range

3 visualizzazioni (ultimi 30 giorni)
johnscape
johnscape il 4 Mar 2017
Risposto: Star Strider il 4 Mar 2017
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?

Risposte (2)

Image Analyst
Image Analyst il 4 Mar 2017
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 il 4 Mar 2017
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.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by