10

This is driving me mad. I am tryng to create some contour plots, but I get them full of labels, so that they are unreadable! I can't even see the lines or read the values because they are too much. I just formatted the numeric output from my script, so that the code I am placing here is not really nice. Anyway, I can get the right contour but I would like to have ONLY ONE label on each contour line, not N. I couldn't find any solution on pgfplots manual. Here is my code:

\begin{tikzpicture}
    \begin{axis}
         [xlabel=$x$,
         ylabel=$y$,
         width=0.48\columnwidth,
                 view={0}{90},
                 ymin=0, ymax=70
                 ]
        \addplot3
             [contour gnuplot,
                         thick
                         ]
            coordinates {
            .....
            };
    \end{axis}
\end{tikzpicture}

I did not post the coordinates because my file was more than 1000 lines. Any idea? Thanks in advance

3
  • 2
    Generally, the PGFPlots algorithm does a pretty good job at deciding where to put the labels. If it doesn't work as you want it to, you could try setting contour/label distance to a value greater than the default of 200pt. Maybe you could try creating a smaller sample of your data that reproduces the undesired behaviour, then we could attempt a more targeted solution.
    – Jake
    Commented Dec 23, 2012 at 19:17
  • 2
    The automatic label placement of pgfplots only has the label distance key to customize its result as indicated by @Jake (however, the initial value is 70pt). If you only want one label per contour line, you can set contour gnuplot={label distance=10000pt}. Pgfplots will always generate one label. You can also disable labels using contour gnuplot={labels=false}. Commented Dec 23, 2012 at 19:37
  • that worked. Iti didn't post only one label each line but more, anyway result was much better Commented Dec 24, 2012 at 10:35

1 Answer 1

9

[answer converted from a comment]

The automatic label placement of pgfplots only has the label distance key to customize its result as indicated by @Jake (however, the initial value is 70pt).

If you only want one label per contour line, you can set contour gnuplot={label distance=10000pt}. Pgfplots will always generate one label, so this disables only the following ones.

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.7}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        title={$x \exp(-x^2-y^2)$},
        domain=-2:2,enlarge x limits,
        view={0}{90},
    ]
   \addplot3[
        contour gnuplot={
            number=14,
            label distance=10000pt,
        },
        thick]
   {exp(0-x^2-y^2)*x};
    \end{axis}
\end{tikzpicture}

\end{document}

You can also disable labels using contour gnuplot={labels=false}.

If you believe that the outcome should be improved somehow (like "move the label somehow" or whatever), you can post feature requests at http://sourceforge.net/projects/pgfplots/ . In that case I would like to ask you to include a full phrase stating the expected behavior.

2
  • thanks for this. On a side node, label distance=10000pt works well on closed contours. Open contours, e.g. this, makes the labels vanish outside the plot. I tried to use anchor=south west and outer xsep, but then the labels are sloped wrongly. What could I do? Should I post a question on that?
    – Sebastian
    Commented Mar 11, 2014 at 16:03
  • That could be a bug. Could you send a minimal working example by mail? My address is in the manual of pgfplots. Commented Mar 11, 2014 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .