Saving plot in app designer without distortion

조회 수: 2 (최근 30일)
Peter Nordström
Peter Nordström 2019년 7월 16일
답변: Kanishk 2025년 1월 4일
I'm working on a project where I plot content in a UIAxes and then save the plot as a png following the code posted by Joost here. The problem I get is that the numbers (1-47) on the plot scale differently than the test of the plot and start to overlap.
The first image is a screen print from the matlab app window and the second is the one that gets saved.
TakBildPrintScreen.png
TakBild.png

답변 (1개)

Kanishk
Kanishk 2025년 1월 4일
In the shared MATLAB Answer, the suggestion is to use "copyobj" to copy the graphics object and save the copied object. This approach may not be copying all the other properties such as font size which results in different font sizes while saving.
To address the issue, you can use "exportgraphics" function to export and save the axes object to an image file. Here is a simple code example for the same.
% Code that executes after component creation
function startupFcn(app)
plot(app.UIAxes, 1:10);
text(app.UIAxes, 6, 6, '40')
text(app.UIAxes, 6.3, 6, '41')
fontsize(app.UIAxes, 7, 'points')
end
% Button pushed function: Button
function ButtonPushed(app, event)
exportgraphics(app.UIAxes, 'exportFig.jpg')
end
The saved image also has same font size.
To learn more about 'exportgarphics', please go through the official MATLAB documentation using the command in the MATLAB command window.
web(fullfile(docroot, 'matlab/ref/exportgraphics.html'))

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by