How to add captions to figures in a LiveScript that also include figure numbers
조회 수: 40 (최근 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!