How to plot a heat map with three vectors?

조회 수: 14 (최근 30일)
Rita
Rita 2018년 5월 30일
댓글: Rita 2018년 6월 1일
I have 3 vectors of hour of day , day of a year and temperature data . The temperature data measured 4 times a day. and for 365 days. I would like to plot a heat map like this

채택된 답변

Akbar
Akbar 2018년 6월 1일
편집: Akbar 2018년 6월 1일
I have made some modifications. The heatmap below Shows highest temp. each hour of a month, for two years.
% creating table (i hope you are using new Version of matlab
% which has table function, otherwise try dataset)
t1 = datetime(2016,01,1,8,0,0);
t2 = datetime(2018,01,1,8,0,0);
t = t1:hours(1):t2;
myTable = table(t',year(t'),month(t'),day(t'),hour(t'));
myTable.Properties.VariableNames = {'date' 'year' 'month' 'day' 'hour'};
a = 0;
b = 40;
r = (b-a).*rand(17545,1) + a;
myTable.temp = r;
% Create categorical arrays from the month
% and hour columns of the table.
% Then determine the unique months and hours
% to use as labels along the x-axis and y-axis.
months = categorical(myTable.month);
hours = categorical(myTable.hour);
xlabels = categories(months);
ylabels = categories(hours);
%Determine the final size of the resulting
%color data based on the number of unique months and hours.
nummonths = numel(xlabels);
numhours = numel(ylabels);
%Convert the categorical months and hours arrays
%into numeric indices to use with the accumarray function.
%Compute the color data as the maximum temperature for each
%month and hour combination using the accumarray function.
%Use NaN for missing month and year combinations.
x = double(months);
y = double(hours);
temps = myTable.temp;
cdata = accumarray([y,x],temps,[numhours,nummonths],@max,NaN);
%Create the heatmap. Label the x-axis and y-axis with the
%months and years, respectively. Color the heatmap cells
%using the computed matrix data.
h = heatmap(xlabels,ylabels,cdata);

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 5월 30일
You can make such a graph using pcolor(). The actual procedure depends on the format your data is available. You might need to use findgroups() and splitapply first to separate your data and then use pcolor() to plot the graph.
  댓글 수: 1
Rita
Rita 2018년 5월 30일
편집: Rita 2018년 5월 30일
Thanks Ameer.I don't think pcolor can plot what I wanted. I would like to use "heatmap" and I also would like to show nans as well.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by