Matlab的XTi​ckLabel中下标​表示问题,谢谢!。

9 ビュー (過去 30 日間)
pbwerd
pbwerd 2023 年 5 月 23 日
回答済み: bdjgerfy 2023 年 5 月 23 日
问题比较初级啊。就是想在fig图的X轴自定义显示内容,用的是这个命令:
set(gca, 'XTickLabel', {'G_1' 'G_2' 'G_3' 'G_4' 'G_5'});
但是G_1这种写法不会将1显示为下标,而是直接显示G_1,请问各位大侠有什么方法?多谢指教!

採用された回答

bdjgerfy
bdjgerfy 2023 年 5 月 23 日
自己做了一个自由标刻度的函数可以解决。有不尽完美之处还望各位指教。
%axis为'x'或'y',分别表示更改x或y刻度
%ticks是字符cell
function settick(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=(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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!