How to get rid of an extra space added by getSnapshotImage

1 次查看(过去 30 天)
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);

采纳的回答

Srijith Kasaragod
Srijith Kasaragod 2021-12-3
编辑:Srijith Kasaragod 2021-12-7
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!

更多回答(0 个)

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by