How do I copy an image of an axes in MATLAB without including the entire figure?
조회 수: 6 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2019년 12월 12일
편집: MathWorks Support Team
2024년 10월 11일
I have an axes, with a plot and legend, inside of a larger figure (with extra components like buttons and tables). I want to copy an image of this axes to the clipboard and paste it in Microsoft Word. I know that I can use the "copygraphics" or "print" function to copy a figure. But I don't want the entire figure, just the axes.
채택된 답변
MathWorks Support Team
2024년 10월 10일
편집: MathWorks Support Team
2024년 10월 11일
There are three ways to copy an image of just the axes to the clipboard:
Consider a simple figure with tabular and plotted data:
x = [1;2;3];
y1 = [1;2;3];
y2 = [1;3;5];
f = figure;
t = uitable(f,'Data',[x y1 y2],'ColumnName',{'x','y1','y2'},'RowName',{},'Units','normalized');
t.Position = [.03 .65 t.Extent(3:4)];
t.Position(1:2) = [.05 .55];
ax = axes('Position',[.5 .1 .45 .8]);
plot(x,[y1 y2]);
legend({'y1','y2'});
1. Hover your mouse over the axes and a toolbar will appear at the top right corner. Hover over the leftmost icon and then select "Copy as image". This will copy an image of your axes to the clipboard exactly as is (including both plot and legend). If you cannot see the axes toolbar, make sure its "Visible" property is set to "on":
2. If you are using MATLAB R2020a or a later release, to achieve this programmatically, use "copygraphics". Specify the axes handle to copy the axes only.
For example,
copygraphics(ax);
3. If you are using a MATLAB release before MATLAB R2020a, an alternative programmatic solution is to use 'ScreenCapture', a File Exchange pick of the week. This code can copy images of figures - as well as specific components within a figure - to the clipboard.
More information can be found on this blog post:
Please note that this function is user-submitted, so it is not officially supported or checked for bugs.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!