Saving plot in app designer without distortion

3 visualizzazioni (ultimi 30 giorni)
Peter Nordström
Peter Nordström il 16 Lug 2019
Risposto: Kanishk il 4 Gen 2025
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

Risposte (1)

Kanishk
Kanishk il 4 Gen 2025
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'))

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by