How can I modify the legend of my graph?
43 views (last 30 days)
Show older comments
Khalid Khawaja
on 29 Feb 2016
Commented: Star Strider
on 29 Feb 2016
Hi ,
I have plotted some data using MATLAB. I need to plot markers for some of the values. The problem is How I can combine legend of two Plot command. This is my code.
x=[1:1:100];
y=x;
plot(y,x,y(1:10:end),x(1:10:end),'bo')
legend('Values a','Values b')
I'd like to get one legend that could be able to show me line and marker in one line.
Regards
0 Comments
Accepted Answer
Star Strider
on 29 Feb 2016
I’m not certain what you’re asking.
See if adding 'Orientation','Horizontal' to your legend call does what you want:
legend('Values a','Values b', 'Orientation','horizontal');
Otherwise if you want a line joining the markers, this will do what you want:
plot(y,x,y(1:10:end),x(1:10:end),'-bo')
7 Comments
Star Strider
on 29 Feb 2016
The usual way to deal with those problems is to use a handle to the original object. That won’t work here because I used two text objects. The only solution I have is to create your own function to write the two text objects, and pass the figure handle to it. It would get the necessary information from the figure handle and write the text objects correctly to it.
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!