Effacer les filtres
Effacer les filtres

How to set different marker and marker edgecolor on single line in Plot?

83 vues (au cours des 30 derniers jours)
Alex Zai
Alex Zai le 14 Sep 2022
Commenté : dpb le 15 Sep 2022
Hello sir!
I want to set different marker and marker edgecolor on single line in Plot? Please, how can i do that, Thanks a lot!
Here example variable x, y. When under the value 12 (red line in photo), i want to set different marker and color for that two points.
x = 1:11;
y = [30 27 31 28 9 34 33 35 33 33 10];
y1 = 12;
p = plot(x,y,'-k', 'Marker', '*', 'MarkerEdgeColor','g');
hold on;
plot(x,y1*ones(size(x)),'LineStyle','--');
hold off;

Réponse acceptée

dpb
dpb le 14 Sep 2022
plot is a single object for each line -- ergo, each line can have only one linestyle (colors, marker, line). To have a second marker/color/etc. means another line...
x = 1:11;
y = [30 27 31 28 9 34 33 35 33 33 10];
y1 = 12;
hL=plot(x,y,'-k', 'Marker', '*', 'MarkerEdgeColor','g');
hold on;
yline(y1,'LineStyle','r--')
ix=(y<y1); % the offending locations
hL(2)=plot(x(ix),y(ix),'xr'); % put red 'X' there...
Can set any/all of the marker properties as desired -- "salt to suit".
  2 commentaires
Alex Zai
Alex Zai le 14 Sep 2022
Thanks a lot! It's work :).
dpb
dpb le 15 Sep 2022
Thanks for feedback; glad to help...
If this resolved the issue, please go ahead Accept the Answer -- let's other know if no other reason...

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by