[Tex/LaTex] Problem in adjusting contour label color and numbr of samples in pgfplot

pgfplots

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},
    ]
    \addplot3[
        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.

enter image description here

Could someone help me?

Best Answer

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},
    ]
    \addplot3[
        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

enter image description here