Does anyone know of an example of how to create a categorical heat map with individual sparklines within each cell? Or have a suggestion on how to use matplotlib's annotation to produce this (or something similar)?
Essentially turning this: Matplotlib heatmap annotation
into this: Heatmap with sparkline
Assuming such a format as input (an arbitrary number of rows for each combination of row/col) and that we want to plot a heatmap with the average
value
perrow
/col
, and a small line for eachrow
/col
combination with the consecutive values:You could plot a heatmap using
sns.heatmap
on the reshaped data (withpivot_table
, here using the mean of the data per group), then rework the data to plot a line on top of it:Example output:
Reproducible input:
Alternative output when
.sample(frac=0.7).sort_index()
is uncommented (to simulate uneven groups):