How to get rid of an extra space added by getSnapshotImage

3 Ansichten (letzte 30 Tage)
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);

Akzeptierte Antwort

Srijith Kasaragod
Srijith Kasaragod am 3 Dez. 2021
Bearbeitet: Srijith Kasaragod am 7 Dez. 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!

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Report Generator Task Examples finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by