I would like to annotate a heatmap with the values that I pass from a dataframe into the function below. I have looked at matplotlib.text but have not been able to get the value
This is because you're using plt.text
after you've added another axes.
The state machine will plot on the current axes, and after you've added a new one with divider.append_axes
, the colorbar's axes is the current one. (Just calling plt.colorbar
will not cause this, as it sets the current axes back to the original one afterwards if it creates the axes itself. If a specific axes object is passed in using the cax
kwarg, it doesn't reset the "current" axes, as that's not what you'd normally want.)
Things like this are the main reason that you'll see so many people advising that you use the OO interface to matplotlib instead of the state machine interface. That way you know which axes object that you're plotting on.
For example, in your case, you could have heatmap_binary
return the ax
object that it creates, and the plot using ax.text
instead of plt.text
(and similar for the other plotting methods).