# Help Making Heat Map with Categorical Y-axis and Continuous X-axis

11 views (last 30 days)
SRB on 19 May 2020
Commented: SRB on 28 May 2020
I have 474 x 3 matrix (attached). Column 1 of the matrix is time, column 2 is the number of times something occurred, and column 3 is a column of dummy variables that identifies what type of event happened.
Here is a truncated example of the matrix:
361.488 0 1001
361.491 0 2001
362.021 0 3001
363.017 3 4001
366.231 0 1001
366.235 0 2001
366.885 0 3001
367.883 2 4001
So, for example, row 1 shows that event 1001 occurred 0 times at time point 361.488. Row 4 shows that event 4001 occurred 3 times at time point 363.017...and so on.
What I would like to do is create a heat map where the categorical dummy variable is on the y-axis, time is on the x-axis, and the categorical variables that occurred at the different time points on the x-axis are colored 'cool' to 'hot' based on the numer of times the event occurred (the number in the second column).
For example, one could imagine that as you read from left to right from the 1001 point on the y-axis that there are a series of cool and warm colors indicating that a fewer or greater number of 1001 events occurred as a function of time.
I have tried doing this using heatmap, pcolor, and imagesc functions and can't get it to do quite what I want.
Any help is much appreciated!

Cris LaPierre on 20 May 2020
This technically achieves what you want, but you have so many X values that it is not very readable. In addition, a time-event pair that does not occur is labeled 'NaN'. By default, this is assigned the color black. This by far dominates the heatmap.
You can explore additional properties of a Heatmap to maybe get this more like what you are expecting.
% convert the array to a table
data = array2table(HeatMapData,"VariableNames",["Time","Counts","Event"]);
% Make event a categorical
data.Event = categorical(data.Event);
% Make time a datetime
data.Time = datetime(data.Time,'ConvertFrom','datenum')
heatmap(data,"Time","Event",'ColorVariable',"Counts")
##### 1 CommentShowHide None
SRB on 28 May 2020
Thanks!

### Community Treasure Hunt

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

Start Hunting!

Translated by