matlab in a plot use annotation for diamond

358 views (last 30 days)
jaribeiro
jaribeiro on 17 Jan 2016
Commented: jaribeiro on 17 Jan 2016
i'm kind of a newbie in matlab, hope that someone can help me!
I'm doing several plots, using "hold on", with different markers and colors in a cycle. I would like to create a legend for the plot. The problem is that not always all the plots will be created, as sometimes the vector will be null, and therefore "legend" is not a good option.
I was thinking to use annotation, but i don't know how to represent the symbols like "Diamond" or "Left-pointing triangle", with colors and filled, using the annotation
For example: how to write this in the form of annotation??
'marker','d','markerfacecolor',[0 1 0],'LineStyle','none','color',rgb('lime')

Answers (1)

Chad Greene
Chad Greene on 17 Jan 2016
Check out the LineSpec table here. Use plot(x,y,'d') for diamond or plot(x,y,'<') for left-pointing triangle. Include 'markerfacecolor' to fill the marker. For example,
plot(x,y,'d','color','r','markerfacecolor','b','markersize',12)
prints a big blue diamond with a red outline.
  1 Comment
jaribeiro
jaribeiro on 17 Jan 2016
i know how to do that, the problem is that in some occasions one or more vectors can be null and therefore it don't do all the plots, but i still need to appear in the legend all the options. Below is my code for the plots:
plot(b0/1000,p0,'marker','o','LineStyle','none','color',rgb('black')) hold on plot(b1/1000,p1,'marker','p','markerfacecolor',[0.5 0.5 0.5],'LineStyle','none','color',rgb('gray'))% hold on plot(b2/1000,p2,'marker','d','LineStyle','none','color',rgb('fuchsia')) hold on plot(b3/1000,p3,'marker','d','markerfacecolor',[0 1 0],'LineStyle','none','color',rgb('lime')) hold on plot(b4/1000,p4,'marker','d','LineStyle','none','color',rgb('blue')) hold on plot(b5/1000,p5,'marker','s','markerfacecolor',[1 0 0],'LineStyle','none','color',rgb('red')) hold on plot(b6/1000,p6,'marker','d','LineStyle','none','color',rgb('gold')) hold on plot(b7/1000,p7,'marker','s','LineStyle','none','color',rgb('aqua')) hold on plot(b8/1000,p8,'marker','^','LineStyle','none','color',rgb('purple')) hold on plot(b9/1000,p9,'marker','^','LineStyle','none','color',rgb('darkgreen'))

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!