How to get rid of an extra space added by getSnapshotImage

조회 수: 2 (최근 30일)
Blue
Blue 2021년 11월 29일
편집: Srijith Kasaragod 2021년 12월 7일
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