How to plot a heat map with three vectors?

13 visualizzazioni (ultimi 30 giorni)
Rita
Rita il 30 Mag 2018
Commentato: Rita il 1 Giu 2018
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

Risposta accettata

Akbar
Akbar il 1 Giu 2018
Modificato: Akbar il 1 Giu 2018
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);

Più risposte (1)

Ameer Hamza
Ameer Hamza il 30 Mag 2018
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 Commento
Rita
Rita il 30 Mag 2018
Modificato: Rita il 30 Mag 2018
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.

Accedi per commentare.

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by