Clear Filters
Clear Filters

How can I modify the legend of my graph?

43 views (last 30 days)
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

Accepted Answer

Star Strider
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
Khalid Khawaja
Khalid Khawaja on 29 Feb 2016
I agree with you. I also searched for this problem, but couldn't get a suitable solution. Your method solves the problem to some extent. In my case, I have many graphs I am thinking of using visio now. It's a great deal of work to change settings of all graphs.
Star Strider
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!