我在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 = [1990; 1990; 1990];
t.Month = [1; 2; 3];
t.datapoint = [5; 7; 8];
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)