fill legend rectangles with color
5 ビュー (過去 30 日間)
古いコメントを表示
hello,
I'd like to fill the legend rectangles in color (not just the frame as in the picture), how it can be done?
thanks!![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/302853/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/302853/image.jpeg)
2 件のコメント
Walter Roberson
2020 年 5 月 27 日
What kind of graphic object are those for? Were you using rectangle() ? Or bar() ?
採用された回答
darova
2020 年 5 月 27 日
Try this example
surf(peaks,'facecolor','none') % plot peaks
surface(membrane,'facecolor','none') % plot membrane
h = legend('surf','memb'); % show legend
h1 = get(h,'children'); % get handle of each object in legend
for i = 1:length(h1) % loop through each object
if strcmp(get(h1(i),'type'),'patch')% if an object is a patch
cc = get(h1(i),'edgecolor'); % get edgecolor
set(h1(i),'facecolor',cc) % set facecolor
end
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/303353/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/303358/image.png)
3 件のコメント
darova
2020 年 5 月 28 日
Maybe you have newer version and there some some difference in handlers
Try to experiment with these
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304643/image.png)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!