首页 > 解决方案 > matlab如何修改图表坐标轴?

问题描述

是否可以在 matlab 的 XData 轴中放置字符而不是数字?例如在这张图表中, 简单图表

我想1 2 3string 1 string 2 string 3X 轴替换。

我的代码是

a=bardata ;
b=barerror ;
ctrs = 1:3;
data = a;
figure(1)
hBar = bar(ctrs, data);
markers = {'x','o','^'};
ctr = [];
ydt = [];
for k1 = 1:size(a,2)
    ctr(k1,:) = bsxfun(@plus, hBar(1).XData, [hBar(k1).XOffset]');
    ydt(k1,:) = hBar(k1).YData;
end
hold on
    errorbar(ctr', ydt', b, '.r')
    legend({'Version 1', 'Version 2'}, 'location', 'northeast');
hold off

标签: matlab

解决方案


尝试这个:

xticks([1 2 3]);
xticklabels({'string 1','string 2','string 3'});

xticks 基本上告诉在哪里放置刻度,并且 xticklabels 是不言自明的。

如果您需要有关标签的更多信息: https ://www.mathworks.com/help/matlab/ref/xticklabels.html


推荐阅读