How to fix/steady the position of a counter in plot title.
1 次查看(过去 30 天)
显示 更早的评论
I have a script for plotting animated surf and trisurf plots. It has a time counter in the title fed by the 'for' loop index. With each redraw, the counter moves position depending on the number of numerals in the number, so it flickers quite annoyingly in the 30 fps resultant video that the script writes.
I've tried specifying the title position with each redraw, specifying its justification and also creating a data-free plot first, holding it and having the animated plot over the top (but I couldn't get that to work). Haven't managed to find a similar problem on Answers.
Extremely grateful for any suggestons of things to try. Cheers.
0 个评论
回答(2 个)
Bjorn Gustavsson
2020-11-25
Perhaps you can use the same type of zero-padding often used for filenames? Something like:
tstr = sprintf('%04d',loop_idx);
Or however large indices you have to make space for. This might not be the prettiest, but perhaps you can use some of the other formating-flags, se the documentation for fprintf for posibilities.
HTH.
0 个评论
dpb
2020-11-25
编辑:dpb
2020-11-25
Use a fixed-width format string to build the string to display...
title(num2str(t1(3)*1000,'Simulation time = %8.3f ms'))
t1 happened to be a variable in my workspace from an earlier Answer; obviously "salt to suit".
You may still see some movement unless you use a fixed-width font as otherwise the rendering of different numbers and number of blanks will result in a little bit of difference in the kerning/width of proportional fonts.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!