我想在barh()
图表的ylabel中使用希腊符号。我尝试了以下方法,但实际上没有用:
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引用:
使Xtick标签和Ytick标签使用相同功能的能力不能使用LaTeX作为其解释器的TEXT对象字体在MATLAB 8.1(R2013a)中。
因此,您需要删除ylabel并手动将其作为文本对象手动创建。然后,您可以使用乳胶解释器。
这里是示例的修改版本,适合您的目的:
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
输出:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS8xdG5iYS5qcGcifQ==” alt =“在此处输入图像描述”>