plot filled rectangle and appear on legend
72 views (last 30 days)
Show older comments
michael
on 29 Nov 2020
Commented: Walter Roberson
on 13 Dec 2020
Hi,
I'd like to have something like that
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/433798/image.png)
I know that I can use rectangle function, but then it is not appearing on a legend.
Any suggestions how to solve the issue?
0 Comments
Accepted Answer
Walter Roberson
on 29 Nov 2020
Use fill() such as
fill([xmin xmax xmax xmin], [ymin ymin ymax ymax], 'facecolor', 'y')
2 Comments
Walter Roberson
on 13 Dec 2020
Record the handle of one of the fill() calls. Pass only that handle to legend() (along with the handles of any other objects you do wish to legend() )
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!