[英]Problem plotting data in Matlab (setting month and year in the x-axis)
我在 MATLAB 中有以下表结构:
Year Month datapoint
1990 1 5
1990 2 7
.
.
.
1995 12 3
我想用 y 轴上的数据点和 x 轴上的 1990_1, 1990_2... 之类的东西来绘制它。
我该怎么做呢?
您可以通过使用get函数获取该对象的句柄,然后直接修改属性来格式化 XAxis 的外观。
% Create example table
t = table();
t.Year = repelem(1990,72,1);
t.Month = [1:72].';
t.datapoint = [5:76].';
plot(t.datapoint)
% Get x axis
xaxis = get(gca,'XAxis');
% Format tick labels
xaxis.TickLabels = compose('%d_%d',t.Year,t.Month);
% Format interpreter
xaxis.TickLabelInterpreter = 'none';
% Limit number of ticks
xaxis.TickValues = 1:numel(t.datapoint);
根据您的评论,只看到每 12 个标签:
indx = 1:72;
indx(12:12:72) = 0;
indx(indx > 1) = 1;
xaxis.TickLabels(find(indx)) = {''}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.