# Library that can overlay a text with a heatmap

I am looking for a library that can overlay a text with a heatmap. I.e., add a highlight with gradient. I would simply define a value for each character: the value would define the highlight/heatmap intensity.

Ideally I should be able to easily call it from python.

• Sounds good. I would also like ot see it handle words, not just characters. And, as well as user-defined, have an option to auto-heat map word frequency. – Mawg Feb 9 '17 at 9:21

You could define a new command LaTeX:

Example from https://arxiv.org/abs/1603.01547 :

\newcommand{\attvis}[2]{\definecolor{att}{rgb}{1, #2, #2} \colorbox{att}{#1}}

[...]

\begin{figure}[t]
\small
\centering%
\begin{tabular}{| p{\dimexpr0.47\textwidth-2\tabcolsep-\arrayrulewidth\relax}|   }
\hline
\hspace{0.25\textwidth}\textbf{...}
\\
%according to a entity21 lawmaker (education policy is super gay, obviously); %\attvis{entity25}{0.86},
%who an op-ed writer for entity28, entity29, claims is being used by entity30 to
%"attract young girls" to her show (uh-huh); the entity36 princess movie "entity40"
%according to radio hosts in entity38 (that dress!); and now, according to a
%potential 2016 entity34 presidential contender, \attvis{entity32}{0.81}, there's prison. yep, %prison.
%stay away from crime, kids. turns ya gay. \attvis{entity32}{0.705}, who ,let me reiterate ,
%is a potential presidential candidate from a major entity54 party
what was supposed to be a fantasy sports car ride at \attvis{@entity3}{0.97} turned deadly when a \attvis{@entity4}{0.47} crashed into a guardrail . the crash took place sunday at the @entity8 , which bills itself as a chance to drive your dream car on a racetrack . the \attvis{@entity4}{.99} 's passenger , 36 - year - old @entity14 of @entity15 , @entity16 , died at the scene , @entity13 said . the driver of the \attvis{@entity4}{0.98} , 24 - year - old @entity18 of @entity19 , @entity16 , lost control of the vehicle , the \attvis{@entity13}{0.82} said .
\\
\hspace{0.25\textwidth}\textbf{...}
\\
\includegraphics[width=0.44\textwidth]{att_map}
\\
\hline
\hline
%\begin{figure}[h!]

% \caption{See that the ....}
% \label{fig:attention_1}
%\end{figure}

officials say the driver , 24 - year - old @entity18 , lost control of a \_\_\_\_\_
\\
\hline

\end{tabular}
\caption{Attention in an example with anonymized entities where our system selected the correct answer. Note that the attention is focused only on named entities.}
\label{tab:goodEx}
\end{figure}

• Is it easily callable form Python, as you requested (from yourself, apparently ;-)? Would I need any Latex knoweldge to use i? – Mawg Feb 9 '17 at 9:23
• @Mawg as far as I know it isn't easily callable from Python :( just needs very limited Latex knoweldge. – Franck Dernoncourt Feb 9 '17 at 18:53