How to get rid of an extra space added by getSnapshotImage

1 vue (au cours des 30 derniers jours)
Blue
Blue le 29 Nov 2021
Hello,
getSnapshotImage seems to be adding an extra space in the annotation of my figures. In the dummy plot below there is no space between the R and the 2 in superscript in the annotation. But when I open the report there is an added space between the R and the 2 in superscript in the annotation. How do I get rid of that added space ?
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('test', 'pdf');
open(rpt)
plot([1,2,3,4], [1,2,3,4])
N = 370;
R = 0.95;
str = ['N = ', num2str(N), ', R^2 = ', sprintf('%.2f', R)];
annotation('textbox', [.15 0.85 0 0], 'string', str, 'FitBoxToText', 'on', 'EdgeColor', 'black');
figure = Figure();
img = Image(getSnapshotImage(figure, rpt));
img.Width = '5.5in';
img.Height = [];
halign = mlreportgen.dom.HAlign('center');
img.Style = [img.Style(:)' {halign}];
delete(gcf);
add(rpt, img);
close(rpt);
rptview(rpt);

Réponse acceptée

Srijith Kasaragod
Srijith Kasaragod le 3 Déc 2021
Modifié(e) : Srijith Kasaragod le 7 Déc 2021
Hi,
The following workarounds were found to resolve the issue of extra space you are referring to:
  • Set 'Interpreter' parameter in 'annotation' function call to LATEX:
annotation('textbox', [.15 0.85 0 0], 'String', str, 'FitBoxToText', 'on', 'EdgeColor', 'black', 'Interpreter','latex');
  • Enclose the operands to the superscipt operation with the default TEX interpreter as follows:
str = ['N = ', num2str(N), ', {R}^{2} = ', sprintf('%.2f', R)];
Hope this helps!

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by