How can I modify the legend of my graph?

34 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2016-2-29
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 个评论
Khalid Khawaja
Khalid Khawaja 2016-2-29
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 2016-2-29
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by