在matlab自带的格式中无法在自定义坐标刻度中使用上角标(上标)和下角标(下标),在标题中可用的_作为下角标和^作为上角标都不行了。 在matlab帮助中写着: from matlab help Note that tick labels do not interpret TeX character sequences (however, the Title, XLabel, YLabel, and ZLabel properties do).
n=length(ticks); tkx=get(gca,'XTick');tky=get(gca,'YTick'); switch axis case 'x' w=linspace(tkx(1),tkx(end),n); set(gca, 'XTick', w, 'XTickLabel', []);%刷新刻度,去掉刻度值 yh=(14*w(1)-w(end))/13;%按坐标轴比例调整刻度纵坐标位置 for i=1:n text('Interpreter','tex','String',ticks(i),'Position',[w(i),yh],'horizontalAlignment', 'center'); end case 'y' w=linspace(tky(1),tky(end),n); set(gca, 'YTick', w, 'YTickLabel', []); xh=(11*w(1)-w(end))/10; for i=1:n text('Interpreter','tex','String',ticks(i),'Position',[xh,w(i)],'horizontalAlignment', 'center'); end end -------------------------- 调用方法为: 例如: >> x=0:0.1:4*pi;plot(x,sin(x));ticks={'G_1' 'G_2' 'G_3' 'G_4' 'G_5'};settick('x',ticks) >> figure;x=0:0.1:4*pi;plot(x,sin(x));ticks={'G_1' 'G_2' 'G_3' 'G_4' 'G_5'};settick('y',ticks)
但是经过试用发现,X坐标轴的刻度的位置不对,于是自己进行了小小的修改,变成如下所示,就很完美了。
function settickfsun(axis,ticks) n=length(ticks); tkx=get(gca,'XTick');tky=get(gca,'YTick'); switch axis case 'x' w=linspace(tkx(1),tkx(end),n); set(gca, 'XTick', w, 'XTickLabel', []);%刷新刻度,去掉刻度值 yh=-0.06*max(tky);%按坐标轴比例调整刻度横坐标的y位置 for i=1:n text('Interpreter','tex','String',ticks(i),'Position',[w(i),yh],'horizontalAlignment','center','VerticalAlignment','bottom'); end case 'y' w=linspace(tky(1),tky(end),n); set(gca, 'YTick', w, 'YTickLabel', []); xh=-0.06*max(tkx);%按坐标轴比例调整刻度纵坐标的x位置 for i=1:n text('Interpreter','tex','String',ticks(i),'Position',[xh,w(i)],'horizontalAlignment', 'center'); end end
转载自:http://blog.sina.com.cn/s/blog_45b486b801018qoj.html在matlab自带的格式中无法在自定义坐标刻度中使用上角标(上标)和下角标(下标),在标题中可用的_作为下角标和^作为上角标都不行了。在matlab帮助中写着:from matlab helpNote that tick labels do not interpret T