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.

Answers (1)

Image Analyst
Image Analyst on 16 Jun 2018
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)"?

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2018a

Asked:

on 16 Jun 2018

Answered:

on 16 Jun 2018

Community Treasure Hunt

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

Start Hunting!