How do I write a legend with multiple lines?

I'm trying to set a legend on the top of a graph that has a lot of data. If I just orientate it horizontally it simply won't fit the screen and I don't want to set it at neither of the sides as I would waste space. So I'm trying to create a multiple line legend with, say, half of the data on one line and the rest of it on the line below. I've looked on the forums and couldn't figure out a way to do so. Is there any way I can do this? I've even tried setting multiple legends but even that won't work.
Thanks!

 採用された回答

Star Strider
Star Strider 2015 年 5 月 27 日

1 投票

This works for me:
ts = sprintf('This is a\ntwo-line title');
title(ts)

6 件のコメント

Arthur Brigatto
Arthur Brigatto 2015 年 5 月 27 日
This works well for the title, but I don't think I can use it with the legend. I want it to be like this:
---data 1 ---data 2 ---data 3
---data 4 ---data 5 ---data 6
Star Strider
Star Strider 2015 年 5 月 27 日
I apparently misread your question.
I looked through the File Exchange and found columnlegend that looks like it will do what you want.
Arthur Brigatto
Arthur Brigatto 2015 年 5 月 27 日
Thanks for the reply!
This almost works, I'm ploting some of the data using the fill function and the columnlegend only works for lines. So it is not 100% solved..
Star Strider
Star Strider 2015 年 5 月 27 日
My pleasure!
You may have to resort to one of the annotation or text functions. I don’t know how you would want to do the area legend entries, so I can’t offer any specific suggestions. Perhaps bold text in the colour of the patch (area) object, or black text overlain on the background colour of the patch object would work.
Arthur Brigatto
Arthur Brigatto 2015 年 5 月 28 日
Hm, showing it on the area might be a good way to do it.. I'll see if it is plausible.
Thanks again!
Star Strider
Star Strider 2015 年 5 月 28 日
My pleasure!
That would work, but I was initially thinking of something like this to go near the legend:
text(xtxt, ytxt, 'This is what the yellow area represents', 'BackgroundColor','y')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by