Hey,
I have a plot full of lines and to not overload the legend I wanted to only describe some major differences between the lines in the legend and the other differenced in a caption. Therefore I need to adapt the legend in a way I dont know how to.
I have plotted 10 lines, always paired two lines with the same color, but differet in linestyle (- and --). In the legend I only want to explain the difference in color and the difference between the linestyle in a caption. To avoid confusion I want to name the different linestyle plots in the same line in the legend, but with the correct linestyle.
e.g:
- /-- (- and -- in color and linstyle like in plot) max values
- /-- (- and -- in color and linstyle like in plot) mean values
But I dont know how to make the linestyle and color of two different plot apear in the same line.
If there is a possibility to do so, maybe someone could tell me how.
Many Thanks in advance
Best regards

1 Kommentar

dpb
dpb am 11 Jan. 2021
I'd guess fiddling around with NumColumns=2 and the line order and label content will be best can do with legend directly. Whether you can actually manage something that looks presentable or not I don't know; didn't have time to actually try anything.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

dpb
dpb am 11 Jan. 2021

2 Stimmen

Found a few minutes -- Actually works better than I had expected...
hL=plot(abs(randn(10,4)));
set(hL(1:2),{'color'},{'r'})
set(hL(3:4),{'color'},{'b'})
set(hL([2,4]),{'linestyle'},{'- -'})
hLg=legend(hL([1,3,2,4]),'/','/','max','mean','NumColumns',2);
resulted in

7 Kommentare

Adam Danz
Adam Danz am 11 Jan. 2021
+1 creative solution; I hadn't thought of that approach.
Marc Laub
Marc Laub am 11 Jan. 2021
yeah thats the way I also did it, but I wanted to get rid of the extra space behind the "/", thats why I thought there is a different solution
dpb
dpb am 11 Jan. 2021
Unless there's a hidden property to let you set the spacing between columns (which I doubt will be), you're at the mercy of where legend wants to draw the second column.
Beyond that, it's using annotations or the like.
KALYAN ACHARJYA
KALYAN ACHARJYA am 11 Jan. 2021
@dpb Sir, I tried for couple of minutes, but did not succeed.
Thanks for the answers +1
> I wanted to get rid of the extra space behind the "/",
If the white space symmetry is the problem you could add space prior to the foward slash.
hLg=legend(hL([1,3,2,4]),' /',' /','max','mean','NumColumns',2);
dpb
dpb am 11 Jan. 2021
Bearbeitet: dpb am 12 Jan. 2021
"@dpb Sir, I tried for couple of minutes, but did not succeed."
I've not tried anything further, either. W/ the old legend that was just a customized axes, you could do most anything inside it that could do in a regular axes; now that they've turned it into this pseudo object, you can't get access to the base axes object any more (at least not without a lot of machinations) and they don't give you free reign with returning the handles of the subobjects of the text strings, etc., either, that before one could mung on.
All in all, they both giveth and taketh away; oftimes the net is not a gain in terms of special effects/needs/wants.
dpb
dpb am 12 Jan. 2021
I did poke around the hidden object properties a little, did not find access to anything that helped in that initial foray. Figure the text objects have to be in there somewhere, but they're really obscured and if are accessible at all will take a lot of handle diving to find them.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Gefragt:

am 11 Jan. 2021

Kommentiert:

dpb
am 12 Jan. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by