How to plot a heat map with three vectors?

13 次查看(过去 30 天)
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