簡體   English   中英

在 Matlab 中繪制數據的問題(在 x 軸中設置月份和年份)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM