How to copy a plot to clipboard programmatically

74 ビュー (過去 30 日間)
Gregory Smith
Gregory Smith 2021 年 5 月 11 日
コメント済み: Adam Danz 2021 年 5 月 21 日
I'm trying to copy a plot to clipbard programmatically.
I have an old data plotting tool bult using guide. It has a cmd button to deploy the plots into a window where the plot is formatted perfectly to comply with our journel figure formatting rules. In that deployed window I can click Edit > Copy Figure to copy the figure to clipbard and maintain all the formatting; however, I want to do that programmatically.
According to the documentation, this should work:
print -clipboard -dbitmap
However, that copies the plotting tool gui, not the deployed figure window.
I also tried:
figure(handles.PlotOptions.DeployHandle)
print -clipboard -dbitmap
That didn't change anything. I cant work out how to set focus to the deployed figure window not the plot tool window.
I also tried:
copygraphics(handles.PlotOptions.DeployHandle,'ContentType','vector')
%and
copygraphics(handles.PlotOptions.DeployHandle)
This copied the correct figure window; however, it trimmed out all the borders.
I just want exactly what happens when you create a plot figure and click Edit > Copy Figure
  1 件のコメント
Adam Danz
Adam Danz 2021 年 5 月 21 日
I also tried:
copygraphics(handles.PlotOptions.DeployHandle,'ContentType','vector')
This copied the correct figure window; however, it trimmed out all the borders.
What does that mean? Could you should us a screenshot? I use copygraphics all the time to do what you're describing.

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

採用された回答

Khaled Hamed
Khaled Hamed 2021 年 5 月 18 日
  2 件のコメント
Gregory Smith
Gregory Smith 2021 年 5 月 21 日
thank you, but both of these options result in the figure being saved to a file. I already have code that does that.
I'm looking to copy the plot to the clipboard so it can quickly be pasted into a document, or email.
Khaled Hamed
Khaled Hamed 2021 年 5 月 21 日
Try
editmenufcn(newFig,'EditCopyFigure');
or
hgexport(newFig,'-clipboard');
or
print(newFig,'-dmeta');
where newFig is the handle of the new invisible figure

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by