MATLAB 条形图标签中的希腊符号
Greek symbols in labels for bar chart in MATLAB
我想在 barh()
图表的 ylabels 中使用希腊符号。我尝试了以下但它并没有真正起作用:
tplot = barh(mdata, 'BarWidth', 0.3);
set(gca,'xgrid','on')
lbl = {'$$\hat{\sigma}_1$$', '$$\hat{\sigma}_2$$', '$$\hat{\sigma}_3$$'};
box off
set(gca,'yticklabel',lbl)
h=findobj(gca,'type','text');
set(h,'Interpreter','latex')
我也试过:
set(gca,'TicklLabelInterpreter', 'tex')
当我执行 get(gca)
时,属性 TickLabelInterpreter
似乎根本不存在!我使用的MATLAB版本是R2013a.
请注意我特地使用latex
作为解释器,而不是tex
,因为tex
不支持\hat
。
根据 MathWorks 的 this 引述:
The ability to make the Xtick labels and Ytick labels utilize the same
font as TEXT objects with LaTeX as their interpreter is not available
in MATLAB 8.1 (R2013a).
因此您需要删除 ylabels 并手动创建新的 ylabels 作为文本对象。然后您可以使用乳胶解释器。
这里是他们的示例的修改版本以适合您的目的:
clc
clear
y = [57,91,105];
tplot = barh(y, 'BarWidth', 0.3);
lbl = {'$$\hat{\sigma}_1$$', '$$\hat{\sigma}_2$$', '$$\hat{\sigma}_3$$'};
%% Generate figure and remove ticklabels
set(gca,'yticklabel',[])
%% Get tick mark positions
yTicks = get(gca,'ytick');
ax = axis; %Get left most x-position
%% Reset the ytick labels in desired font
for i = 1:length(yTicks)
%Create text box and set appropriate properties
text(ax(1) - .3,yTicks(i),lbl{i},...
'HorizontalAlignment','Right','interpreter', 'latex','FontSize',18);
end
输出:
我想在 barh()
图表的 ylabels 中使用希腊符号。我尝试了以下但它并没有真正起作用:
tplot = barh(mdata, 'BarWidth', 0.3);
set(gca,'xgrid','on')
lbl = {'$$\hat{\sigma}_1$$', '$$\hat{\sigma}_2$$', '$$\hat{\sigma}_3$$'};
box off
set(gca,'yticklabel',lbl)
h=findobj(gca,'type','text');
set(h,'Interpreter','latex')
我也试过:
set(gca,'TicklLabelInterpreter', 'tex')
当我执行 get(gca)
时,属性 TickLabelInterpreter
似乎根本不存在!我使用的MATLAB版本是R2013a.
请注意我特地使用latex
作为解释器,而不是tex
,因为tex
不支持\hat
。
根据 MathWorks 的 this 引述:
The ability to make the Xtick labels and Ytick labels utilize the same font as TEXT objects with LaTeX as their interpreter is not available in MATLAB 8.1 (R2013a).
因此您需要删除 ylabels 并手动创建新的 ylabels 作为文本对象。然后您可以使用乳胶解释器。
这里是他们的示例的修改版本以适合您的目的:
clc
clear
y = [57,91,105];
tplot = barh(y, 'BarWidth', 0.3);
lbl = {'$$\hat{\sigma}_1$$', '$$\hat{\sigma}_2$$', '$$\hat{\sigma}_3$$'};
%% Generate figure and remove ticklabels
set(gca,'yticklabel',[])
%% Get tick mark positions
yTicks = get(gca,'ytick');
ax = axis; %Get left most x-position
%% Reset the ytick labels in desired font
for i = 1:length(yTicks)
%Create text box and set appropriate properties
text(ax(1) - .3,yTicks(i),lbl{i},...
'HorizontalAlignment','Right','interpreter', 'latex','FontSize',18);
end
输出: