how to make a heatmap for a monthly time serie?
7 ビュー (過去 30 日間)
古いコメントを表示
I have a monthly time series from jan1971 to dec 1986.
I want to make a heatmap to show the value of each month in each region.
whaen I use the heatmap structure, I should write the name of x-values. but they are192 and I can not write all of them.
xvalues = {'Jan-1971', Feb1971',..., 'Dec 1986'};
yvalues = {'A','B','C','D''};
h = heatmap(xvalues1,yvalues1,cdata1);
could you please let me know the best way to show the xvalues?
could you make the heatmap with the attached data?
0 件のコメント
採用された回答
Kostas
2019 年 12 月 3 日
Based on the heatmap documentation
tbl = readtable('heatmap.test.xlsx');
months = categorical(tbl.Var2);
years = categorical(tbl.Var1);
xlabels = categories(months);
ylabels = categories(years);
nummonths = numel(xlabels);
numyears = numel(ylabels);
x = double(months);
y = double(years);
A = tbl.A;
cdata = accumarray([y,x],A,[numyears,nummonths],@mean,NaN);
h = heatmap(xlabels,ylabels,cdata);
6 件のコメント
Kostas
2019 年 12 月 3 日
Unfortunately i do not know how/if this can be done in heatmap. One solution could be to save the image in vector format and then change the labels you want using an image proseccing software.
Something else you could do so as to seem nicer, it would be to make a heatmap for each month seperately.
For example to get just for January you could change the "xDisplayData" as follow
xDisplay = h.xDisplayData;
Jan = xDisplayData(1:12:end);
h.xDisplayData = Jan;
And you can do the same for the rest of the months
% February
Feb = xDisplayData(2:12:end);
h.xDisplayData = Feb;
その他の回答 (1 件)
Sean de Wolski
2019 年 12 月 3 日
Convert your x values to datetime. Then heatmap will just work:
dt = datetime('now'):hours(1):datetime('tomorrow');
v = rand(10,numel(dt));
heatmap(dt, 1:size(v,1), v)
5 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!