There is a similar question like mine, but I am not satisfied with the answer, because the axis labels there are coordinates, while I am looking to also have the column and index labels written as text as in seaborn.
This is the output of from seaborn which I want to reproduce (never mind the colormap).
Here's the python code I use to generate an output for pgfplots to use.
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
for i in range(len(df.index)):
for j in range(len(df.columns)):
f.write("{} {} {}\n".format(j,i,df.values[i][j]))
f.write("\n")
generate_file(df)
This create mwe.dat with the following content:
0 0 3
1 0 10
0 1 2
1 1 15
And this is my latex mwe for my current solution, lacking the text labels and the values written in the middle:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90},
colorbar,
]
\addplot3[matrix plot,point meta=explicit] file {mwe.dat};
\end{axis}
\end{tikzpicture}
\end{document}
This currently outputs this:
So I have two questions:
- how to add text labels to axes, instead of coordinates?
- how to write the value in the middle of the cell?
Since I will be using python anyway to generate the original dataframes, it is okay if I need python to actually generate the entire latex code, but I would prefer a solution, where python only generates a data file containing all info needed for the plot (I want to avoid changing things by hand).




mwe.datto the question as well, so people don't have to run your Python code. Edit: and if I do run the Python code, the LaTeX example throws an error. – Torbjørn T. Jul 28 '19 at 16:10mwe.dat. – fbence Jul 28 '19 at 16:37