Combining linestyle in legend.

Hi, I have a code that produce the following figure:
As a minimal example:
f1=rand(1,100);
f2=rand(1,100);
f3=rand(1,100);
f4=rand(1,100);
figure;
plot(x,f1,'b',x,f2,'b:',x,f3,'r',x,f4,'r:')
legend('Horizontal chain','','Diagonal chain','')
I would like to clarify that each string of text designate each color of the plot by putting the text in the middle of 2 entry of legend or by combining the 2 linestyle in one like so :
But I couldn't find any way to do this. Thank you for your help.

Antworten (1)

Image Analyst
Image Analyst am 16 Jun. 2018

1 Stimme

I think you'd have to find the legend's lines' locations with findobj(), and use fill() or patch() exactly where you want the gray patch (to cover up existing line), and use plot() to draw a line at the new line location- could be tricky.
How about just using appropriate working, like "Horizontal Chain (Lower Limit)" and "Horizontal Chain (Upper Limit)"?

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018a

Gefragt:

am 16 Jun. 2018

Beantwortet:

am 16 Jun. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by