# Problem in adjusting contour label color and numbr of samples in pgfplot

I am trying to create a contour plot using TikZ. I have two questions:

1. How can I change the contour labels color to all black?
2. Is it normal that gnuplot responds slow for creating smoother contour lines? what is the best way of creating a smooth contour line?

The code that I used is as follows:

\begin{tikzpicture}
\begin{axis}[
title = {$\omega_\phi\left(x, \sigma\right) = \frac{\Gamma}{\pi{R_c}^2}\exp\left[-\frac{\left(x-x_0\right)^2+\left(\sigma-R_0\right)^2}{{R_c}^2}\right]$},
xmin=1.5, xmax=3.5,
ymin=1.5, ymax=3.5,
view={0}{90},
]
contour gnuplot = {contour label style={draw=black},},
samples=10,
contour/draw color={black},
]
{1/3.1415/0.25^2*exp(-((x-2.5)^2+(y-2.5)^2)/0.25^2)};
\end{axis}
\end{tikzpicture}


When I want to create a smoother plot by using for example 200 samples, It takes a long time to respond. Is this normal? Because I have a super powerful computer. Even with 200 sample points, it does not produce the smooth contour line that I want. I am thinking of using 1000 sample points which takes forever. Everytime I want to compile my paper, I have to wait for a long time for a figure to see the whole PDF of my paper. Is there a better and faster way of creating a smooth contour lines?

Also, the label colors are mapped. I tried to force it to black but it used mapped color. The following is result of the above code using 10 samples.

Could someone help me?

-
1. contour gnuplot = {contour label style={nodes={text=black}}}, –  Qrrbrbirlbel Mar 2 '13 at 23:39
With the fix of my previous comment, the samples settings do affect the output. Regarding compilation time check section 32 “Externalization Library” of the PGF manual and tikz-external on TeX.SX. The standalone class/package my help here, too. –  Qrrbrbirlbel Mar 3 '13 at 0:00
Thanks @Qrrbrbirlbel. I used standalone package with no problem. Is there anyway that the package automatically detect the size of the tikspicture instead of manually set the document geometry using \usepackage[width=3.00in, height=4.00in]{geometry}? –  A2009 Mar 3 '13 at 2:07
I must admit, I have never used TikZ and standalone together, I only have seen it being suggested on TeX.SX. Have you taken a look into the standalone manual? You might also browse question tagged with tikz-pgf and standalone‌​. The \tikzexternalize approach would be much better because its built in TikZ. Finally, you can always ask another question –  Qrrbrbirlbel Mar 3 '13 at 2:44
You can also try to not use --shell-escape, so that gnuplot will not be executed and the values are read directly from the file. –  Qrrbrbirlbel Mar 3 '13 at 22:40

The initial value for the /pgfplots/contour/every contour label key—to which you append with the contour label style key—is (pgfplots manual, p. 117,and pgfplotsplothandler.code.tex, ll. 1877ff.):

\pgfplotsset{
contour/every contour label/.style={
sloped,
transform shape,
inner sep=2pt,
every node/.style={mapped color!50!black,fill=white},
/pgf/number format/relative={\pgfplotspointmetarangeexponent},
}
}


Interesting enough, the initial color (mapped color!50!black) as well as the fill color (to overdraw the plot itself) is set inside the every node style. Why is that so?

Taking a look into pgfplotsplothandlers.code.tex, lines 2071ff., we can see that the every contour label is in fact applied to a scope and not a node. Sneaky!

We can also add stuff to the every node style with either every node/.append style or its short-cut nodes. But use text=black because solely black will also activate a black fill color, and draw=black will only draw the shape’s border.

Now the samples option does actually take effect.

## Code

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = {$\omega_\phi\left(x, \sigma\right) = \frac{\Gamma}{\pi{R_c}^2}\exp\left[-\frac{\left(x-x_0\right)^2+\left(\sigma-R_0\right)^2}{{R_c}^2}\right]$},
xmin=1.5, xmax=3.5,
ymin=1.5, ymax=3.5,
view={0}{90},
]
contour gnuplot={contour label style={every node/.append style={text=black}}},
samples=100,
contour/draw color={black},
]
{1/3.1415/0.25^2*exp(-((x-2.5)^2+(y-2.5)^2)/0.25^2)};
\end{axis}
\end{tikzpicture}
\end{document}


## Output

-

The solution to increasing the speed is to use a proper domain size. Using domain key as an option to \addplot3 improves the speed while generating smooth contour lines. Here samples=100 and domain=2:3.

\documentclass[crop=true,border=0mm]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
axis on top,
title = {$\omega_\phi\left(x, \sigma\right) = \frac{\Gamma}{\pi{R_c}^2}\exp\left[-\frac{\left(x-x_0\right)^2+\left(\sigma-R_0\right)^2}{{R_c}^2}\right]$},
xmin=2, xmax=3,
ymin=2, ymax=3,
view={0}{90},
xlabel = {$x$},
ylabel = {$\sigma$},
]
domain=2:3,
contour gnuplot =
{%
contour label style=
{%
nodes={text=black},
/pgf/number format/fixed,
/pgf/number format/fixed zerofill=true,
/pgf/number format/precision=1,
},
},
samples=100,
contour/draw color={black},
contour/label distance=100pt,
contour/labels over line,
]
{1/3.1415927/0.25^2*exp(-((x-2.5)^2+(y-2.5)^2)/0.25^2)};
\end{axis}
\end{tikzpicture}

\end{document}


It results to the following picture.

-