I want to add a legend to a pgfplots
contour plot that is generated using the contour prepared
option. The legend should contain the colors of the various levels and show the value associated with a given level. This post suggests a way that originally did not work (in 2013) but I assume should work in the current version of pgfplots
. However, the output only lists one legend entry and not two.
Here is the MWE:
\documentclass[border=5mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0.0,xmax=1.0,ymin=0.0,ymax=1.0,
legend image post style={
sharp plot,
draw=\pgfkeysvalueof{/pgfplots/contour/draw color},
},
legend entries={foo,bar}]
\input{data.tex}
\end{axis}
\end{tikzpicture}
\end{document}
The file data.tex
contains the following:
\addplot[contour prepared={labels=false}]
table {
0.1 0.9 1.0
0.9 0.2 1.0
0.1 0.8 0.1
0.9 0.1 0.1
};
The data is contained in a separate file because in my real application the isolines are computed by a separate code. I kept it like this because I don't know whether this will make a difference as far as the legend is concerned. The output of the two files above is:
So there appear to be two problems:
- It only shows "foo".
- The color is black and not red.
What I would like to get is (produced with plot table
, so not a contour plot):
contour prepared
option or not? I have a solution without that option, but your question seems ambiguous on this point.