matlab - matlab如何修改图表坐标轴?
问题描述
是否可以在 matlab 的 XData 轴中放置字符而不是数字?例如在这张图表中,
我想1 2 3
用string 1 string 2 string 3
X 轴替换。
我的代码是
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
解决方案
尝试这个:
xticks([1 2 3]);
xticklabels({'string 1','string 2','string 3'});
xticks 基本上告诉在哪里放置刻度,并且 xticklabels 是不言自明的。
如果您需要有关标签的更多信息: https ://www.mathworks.com/help/matlab/ref/xticklabels.html
推荐阅读
- html - 我可以在 HtmlService 和 HtmlOutput 对话框中格式化文本吗?
- regex - 正则表达式:删除最后一个下划线后的所有内容
- spring-boot - Google Secret Manager 机密未加载到应用程序属性中 - Spring Boot - App Engine
- c# - 如何让多个视图模型查看布尔变量的变化?
- c# - 用于使用 StringBuilder 显示多个 HTML 页面而不是仅显示一个 (ASP.NET) 的语句
- r - 在R ggplot中的数据点中的两点之间绘制一条线
- rust - 如何镜像子像素的矢量?
- python - 使用 group_by 关联进行多个非常不同的操作
- spring - HTTP 状态 404 - 在 Spring Boot 中调用 url 时未找到
- computer-vision - 如何减轻和忽略计算机视觉中的恒定旋转(卡尔曼滤波器、光流)