Greek letters in axes labels are not working

橙三吉。 提交于 2019-12-18 04:26:14

问题


I'm trying to use Greek letters in my xlabel of a plot. Every solution on the internet says that Matlab will accept tex. But instead of the delta-symbol my x-axis is simply labeled 'D'

a = plot(0:40, y);
hold on

plot(delta_T,brechkraft, 'x')
errorbar(delta_T, brechkraft,delta_b,'x');

title('2mm Oelschicht');


xlabel('\Delta');
ylabel('Brechkraft D in 1/cm');
annotation('textbox', [.2 .8 .1 .1],...
    'String', {'Fit: f(x) = m*x + b',    ['m = ', num2str(p(1)) ],    ['b = ', num2str(p(2)) ]});
shg
hold off

saveas(a, 'abc1.png','png');

回答1:


It's a little curious, your syntax seems alright. Have you screwed up some fonts of your system? Or maybe your 'interpreter' is set to none (doc text props)?

Check it with (hx = handle of xlabel):

get(hx, 'Interpreter')

and set it with:

set(hx, 'Interpreter', 'tex')

If that is not working, as a first workaround you could try to activate the Latex interpreter instead of the usually default tex.

x = 0:40;
y = x.^2;

plot(y,x, 'x')
title('\alpha \beta \gamma');

hx = xlabel('Symbol $\sqrt{\Delta}$  ','interpreter','latex');
hy = ylabel('Symbol $\sqrt{\epsilon}$','interpreter','latex');


But actually for simple greek letters, that is not necessary!

with the default tex interpreter:

hx = xlabel('\Delta');
hy = ylabel('\epsilon');

is working too:

but used with latex syntax delta is not recognized anymore:

xlabel('Symbol $\sqrt{\Delta}$  ','interpreter','tex');
ylabel('Symbol $\sqrt{\epsilon}$','interpreter','tex');

Other ideas:

What font does it return when you type: get(0,'DefaultAxesFontName')? Does it work when you set it to Helvetica or Arial?

set(0,'DefaultAxesFontName','Helvetica');

It is also reported that on some systems (e.g. Ubuntu 12.xx) you need to install tex fonts first.



来源:https://stackoverflow.com/questions/21103033/greek-letters-in-axes-labels-are-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!