Extra space in saved figure before subscripts or superscripts
Show older comments
I have plot axis labels that use subscripts and/or superscripts. The figures look exactly as they should when I plot them in Matlab. When I save them, I get an extra space before the subscript or superscript. WHY???? I've done this lots of times and never had this problem.
I've attached an example. The code for the example label is:
ylabel('PSD [m^2/s]','fontsize',14)
I've also tried putting {} around the 2, but it doesn't change anything. I can add latex as the interpreter, but then the font changes and I want the default font.
UPDATE: I just noticed that there's more space before or after any latex text. I used a \times in another label and there's more space before it, but some subscripts have a little space after them. I'm not sure if there's a pattern to this.
6 Comments
Daniel
on 26 Mar 2021
Robert U
on 31 Mar 2021
Hi Daniel,
what Matlab version have you been using? I tried to reproduce the described issue with Matlab 2019b and was not able to:
fh = figure;
ah = axes;
ylabel('PSD [m^2/s]','fontsize',14)
saveas(fh,'test.png')
saveas(fh,'test.eps')
saveas(fh,'test2.eps','epsc')
print(fh,'testPrint','-dpng')
print(fh,'testPrint','-deps')
The figure looks similar to the original.
Kind regards,
Robert
Robert U
on 12 Apr 2021
Hi Daniel,
I cannot reproduce the described issue, using your example.
fh = figure;
ah = axes;
plot(ah,rand(size(1,10)),rand(size(1,10)))
xlabel(ah,'here is super^{script} to see')
ylabel(ah,'here is sub_{script} to see')
saveas(fh,'test_saveas.eps','epsc')
print(fh,'test_print','-deps')

Kind regards,
Robert
Daniel
on 12 Apr 2021
Answers (2)
Enrico Camporeale
on 12 May 2021
0 votes
Try changing the intepreter to latex and put the symbol with super/subscripts within $$
Andrea Bonfanti
on 30 Jul 2021
Edited: Andrea Bonfanti
on 30 Jul 2021
Dear Daniel,
I'm using Octave 4.2.2 for Linux and have faced the same issue, but apparently just from time to time, hence the difficulty to understand the reason.
Now I've found the bug: If you want to add subscripts/superscripts to a given word (say w_s), then every word before w_s must have a subscript/superscript as well to avoid the extra blank in w_s. Looking at your example, a workaround to fix the issue is:
ylabel('PSD_{} [m^2/s]','fontsize',14)
where you create a fictitious subscript to PSD.
Hope this helps,
Andrea
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
