Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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}
share|improve this answer
    
Thanks @Andrew. It works fine when the number of samples are low. There is one problem. Since I want to have a smooth contour line, I used samples=2000. Even using contour/label distance=10000pt does not produce the contour levels to have only one label. Could you please comment on the sample size? All my packages are updated to their latest version. –  A2009 Mar 5 '13 at 2:32
    
You are right, when the number of samples is high, the label distance option seems to not have the desired effect. In my example, samples=130 is fine, samples=131 causes the labels to be misplaced. My guess is that this some arthmetic overflow. Note that samples=100 gives a fairly smooth plot in my example. –  Andrew Swann Mar 5 '13 at 11:46
    
PS your example compiles without label problems for samples=250 and is reasonably smooth. Testing higher values is taking too much time on my machine. –  Andrew Swann Mar 5 '13 at 12:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.