[Tex/LaTex] Problem in increasing the distance between labels in contour plot in a TikZ picture

pgfplots

I am having problem in increasing the distance between the labels in a contour plot in a TikZ picture. I tried a value from 10 to 10000 for the key contour/label distanc just to have only one label on each contour level. All I tried didn't give me the result I want. Is there something that I am missing?

Here is the code I used:

\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$},
            ]
            \addplot3[
                    contour gnuplot = {contour label style={
                                nodes={text=black},
                                /pgf/number format/fixed,
                                /pgf/number format/fixed zerofill=true,
                                /pgf/number format/precision=1,}},
                    samples=2000,
                    contour/draw color={black},
                    contour/label distance=1000,
            ]
            {1/3.1415927/0.25^2*exp(-((x-2.5)^2+(y-2.5)^2)/0.25^2)};
        \end{axis}
    \end{tikzpicture}

\end{document}

I couldn't get contour/label distance=1000, to work for my case. The following is the picture of the above code with samples=2000 and contour/label distance=1000,. I would like to have only one label on each contour.

enter image description here

Could someone help me?

Best Answer

contour/label distance is a length and needs some units, e.g. you should write 1000pt rather than just 1000. The default value is 70pt. Here are two cruder plots with different values for this parameter:

Sample output

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

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        axis on top,
        xmin=-1, xmax=1,
        ymin=-1, ymax=1,
        view={0}{90},
        xlabel = {$x$},
        ylabel = {$\sigma$},
        ]
        \addplot3[
                contour gnuplot = {contour label style={
                            nodes={text=black},
                            /pgf/number format/fixed,
                            /pgf/number format/fixed zerofill=true,
                            /pgf/number format/precision=1,}},
                contour/draw color={black},
                contour/label distance=1000pt,
        ]
        {exp(-(x^2+y^2)};
    \end{axis}
\end{tikzpicture}


\begin{tikzpicture}
    \begin{axis}[
        axis on top,
        xmin=-1, xmax=1,
        ymin=-1, ymax=1,
        view={0}{90},
        xlabel = {$x$},
        ylabel = {$\sigma$},
        ]
        \addplot3[
                contour gnuplot = {contour label style={
                            nodes={text=black},
                            /pgf/number format/fixed,
                            /pgf/number format/fixed zerofill=true,
                            /pgf/number format/precision=1,}},
                contour/draw color={black},
                contour/label distance=50pt,
        ]
        {exp(-(x^2+y^2)};
    \end{axis}
\end{tikzpicture}

\end{document}

Adding a samples option works, but only up to a certain threshhold. Here is the case with samples=100 which is as expected. If you change to samples=131 then the label spacing changes, perhaps due to some overflow problem.

samples=100

Sample smooth output

samples=131

Sample wrong labelling

% arara: pdflatex: { shell: yes }
\documentclass[crop=true,border=0mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        axis on top,
        xmin=-1, xmax=1,
        ymin=-1, ymax=1,
        view={0}{90},
        xlabel = {$x$},
        ylabel = {$\sigma$}]
        \addplot3[samples=100,
                contour gnuplot = {contour label style={
                            nodes={text=black},
                            /pgf/number format/fixed,
                            /pgf/number format/fixed zerofill=true,
                            /pgf/number format/precision=1}},
                contour/draw color={black},contour/label distance=1000pt]
        {exp(-(x^2+y^2)};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}[
        axis on top,
        xmin=-1, xmax=1,
        ymin=-1, ymax=1,
        view={0}{90},
        xlabel = {$x$},
        ylabel = {$\sigma$}]
        \addplot3[samples=100,
                contour gnuplot = {contour label style={
                            nodes={text=black},
                            /pgf/number format/fixed,
                            /pgf/number format/fixed zerofill=true,
                            /pgf/number format/precision=1}},
                contour/draw color={black},contour/label distance=50pt]
        {exp(-(x^2+y^2)};
    \end{axis}
\end{tikzpicture}

\end{document}
Related Question