How to add captions to figures in a LiveScript that also include figure numbers
38 次查看(过去 30 天)
显示 更早的评论
Hello, I am using Live Editor to create a professional report that can be automatically generated with data. I am attempting to add captions to the figures, and have been unsuccessful at:
- Center-justifying the caption
- Reducing the caption font size
As an example, I have inserted a figure manually, and directly below that I have this code:
figureSpec = "Figure %d: Results vs. Time";
figureNumber = figureNumber+1;
strjust(fprintf(figureSpec,figureNumber),'center');
"figureNumber" has been established at the beginning of the LiveScript.
The overall objective here is to have figure numbers that will auto-update if I happen to remove a prior figure, or include extra figures. It doesn't seem to be an option to add figure numbers to captions, or even captions to figures for that matter. Any suggestions would be great, thanks!
2 个评论
Kevin Holly
2022-1-21
Here are a few ideas:
Is your figure on a single axes? If so, you could try
xlabel(['Figure ' num2str(figureNumber) ': Results vs. Time'])
You could also manually insert spaces
figureSpec = " Figure %d: Results vs. Time";
or tabs
figureSpec = "\t\t\tFigure %d: Results vs. Time";
回答(1 个)
Ankit
2022-1-21
编辑:Ankit
2022-1-21
@Cory Dinkle.. I would recommend if you can use annotations. With annotations it is easy to change different properties like alignment, font size, name etc very easily. I hope this could help you to generate your report as expected.
close all;
figure;plot(rand(1,5));
xlabel('X-Axis');ylabel('Y-Axis')
captionFigure()
figure;
data = [2 4 6 7 8 7 5 2];
stem(data)
captionFigure()
figure;plot(1:10);
captionFigure()
function captionFigure()
figList = sort(get(0,'Children'));
i = length(figList);
figureSpec = {['Figure: ' num2str(i) ' Results vs. Time']};
dim = [0.1, 1.0, 0.8, 0.0];
a = annotation('textbox', dim, 'String', figureSpec, 'FitBoxToText', 'on', 'LineStyle', 'none');
a.Color = 'red';
a.FontSize = 12;
a.HorizontalAlignment = 'center';
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!