MATLAB Answers

Exporting only the plot legend to a jpg file

15 ビュー (過去 30 日間)
Joe Lettieri
Joe Lettieri 2021 年 3 月 31 日
コメント済み: Joe Lettieri 2021 年 6 月 25 日
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: 9.8.0.1323502 (R2020a)

採用された回答

Nikhil Sapre
Nikhil Sapre 2021 年 6 月 25 日
Hi Joe,
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;
figure;
p1 = plot([1:10], [1:10], '+-');
hold on;
p2 = plot([1:10], [1:10]+2, 'o--');
legend('text1', 'text2');
set(p1, 'visible', 'off');
set(p2, 'visible', 'off');
set(gca, 'visible', 'off');
exportgraphics(gcf,'test.jpg');
Thanks,
Nikhil.
  1 件のコメント
Joe Lettieri
Joe Lettieri 2021 年 6 月 25 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by