Export to SVG changes symbols on axes

11 views (last 30 days)
Greetings MATLAB community,
while experimenting with figure exports, I found that, whenever I have a plot that has an exponential scaling factor attached to the axis and export it to SVG it will change the "x" symbol into a "#" symbol. The example is very easy:
plot(1e6*rand(10), 'o')
print(gcf, 'test', '-dsvg')
The plot directly exported to png (left) is fine, but exported to svg and then to png (right) is not:
I am, of course, aware that this problem could be avoided by exporting to a different format of by changing the tick labels. This question is aimed at understanding why this is happening, if it is intended and I am just doing something wrong or if it is indeed a bug.
I am grateful for any insights and hope everyone has a nice day.
Best regards, Fabian.

Accepted Answer

Richard
Richard on 29 Dec 2020
Edited: Richard on 29 Dec 2020
Hello Fabian, its almost 7 years later, but I have found solution. For some odd reason, if you change property of axes 'FontName' to different font type (Palatino linotype, Times new roman ...), the 'x' in exponent is showing properly. I don't know why tho. If you use multiple axes (subplot, axes, zoom ...), or mix them with graphical objects (text) with different Font types, it will also lead to wrongly generated '#' instead of 'x'.
This code outputs svg file without problem (tested on Matlab R2018a):
f=figure;
ax=gca;
plot(ax,1e6*rand(10), 'o');
set(ax,'FontName','Palatino linotype');
saveas(f, 'test', 'svg');
EDIT: If you list present system fonts by function:
d=listfonts
the fonts like Times New Roman, are written with capital letters, if you use them in that way in set of property 'FontName', it won't work, and the exponent will show '#'. But if you write them in lowercase , it works even with helvetica, so this is problem of font selection by Matlab. Hope it will help others.
  1 Comment
Frauke Gellersen
Frauke Gellersen on 29 Oct 2021
Edited: Frauke Gellersen on 29 Oct 2021
I just faced the same issue and could confirm the behaviour described here.
However, I also noticed that the generated svg changes.
  • With 'Helvetica' I have the x to # problem.
  • With 'helvetica' the x remains an x, but it is not a Text in Inkscape. It turns into a path.
That looks the same of course, but editing the text in Inkscape becomes difficult and if you import into LaTeX there will be no syntax recognition!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!