I use the example of plotmf
function in the document and at the same time, I want to change the font of x
label. So I use the code below:
fis = readfis('tipper');
plotmf(fis,'input',1)
xlabel('\fontname{宋体} 论域')
ylabel('\fontname{宋体} 隶属度')
But the xlabel
shows it in its original state as \fontname{宋体} 论域
, and the ylabel
is what I want. The figure is below:
So why does the fontname
command in xlabel
not work?
xlabel
and ylabel
in the code, for thinking the failure may occur only at the first label
. But it is still the xlabel
that doesn't work.plot
. Then both xlabel
and ylabel
work properly.So I think the key point is the definition of xlabel
of plotmf
function.
MATLAB R2023b.
Then I use another method avoiding the fontname
in label
using gca
as
fis = readfis('tipper');
plotmf(fis,'input',1)
xlabel('论域')
ylabel('\fontname{宋体} 隶属度')
set(gca, 'FontName', '宋体');
And it works. But I want to simultaneously show different fonts in a label
, such as xlabel('\fontname{宋体} 时间\fontname{Times new roman} (s)')
, and gca
fails.
So this is not a good method, and it doesn't explain the issue.
This is likely caused by this function setting the interpreter used by the label. Each text object has an Interpreter
property that can be set to 'tex'
(default), 'latex'
or 'none'
. Putting it back to the default value should fix this:
fis = readfis('tipper');
plotmf(fis,'input',1)
xlabel('\fontname{宋体} 论域', 'Interpreter', 'tex')
ylabel('\fontname{宋体} 隶属度')
But an easier way to set the font is by using the FontName
property, which not only applies to the axes as a whole, but can be set to each text object:
xlabel('论域', 'FontName', '宋体')