How to get rid of an extra space added by getSnapshotImage

3 visualizaciones (últimos 30 días)
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);

Respuesta aceptada

Srijith Kasaragod
Srijith Kasaragod el 3 de Dic. de 2021
Editada: Srijith Kasaragod el 7 de Dic. de 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!

Más respuestas (0)

Categorías

Más información sobre MATLAB Report Generator Task Examples en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by