Exporting only the plot legend to a jpg file
68 ビュー (過去 30 日間)
Joe Lettieri 2021 年 3 月 31 日
I have an odd case where I want to export the legend (only) of a plot to a jpeg file. That is, I don't what the whole figure, or even the axes - just the legend. It seems that exportgrpahics cannot do that. Is there another way, or do I have to resort to a screen shot :(
I'm running MATLAB Version: 184.108.40.2063502 (R2020a)
Nikhil Sapre 2021 年 6 月 25 日
You can try something like this to turn of visibility of your plots, and axis object. This will export only the Legend from the figure.
clear all; close all;
p1 = plot([1:10], [1:10], '+-');
p2 = plot([1:10], [1:10]+2, 'o--');
set(p1, 'visible', 'off');
set(p2, 'visible', 'off');
set(gca, 'visible', 'off');
Heather 2022 年 11 月 15 日
編集済み: Heather 2022 年 11 月 15 日
@Nikhil Sapre, this looks like a great solution. One question: I'm finding that the legend text looks a bit grayed out. (Using Matlab 2020b.) Do you have any tips on how to avoid that? I've tried explicitly noting 'TextColor','k' in the legend options but that doesn't seem to help.
その他の回答 (0 件)
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!