7

I plot tabular data wherein none of the y-values of the data go above 1.0. In the resulting plot, however, there are a couple of peaks that go beyond 1.0, giving a false impression about those data points: enter image description here

This is not visible when I plot with marks, but I need to use "no marks" because it is otherwise far too busy (80 points in a small plot).

How can I prevent this?

Update: Per Jake's request, here's a minimal example that shows the described behaviour:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
    \begin{figure}[ht]
        \begin{tikzpicture}
            \begin{axis}[no markers, grid=major]
                \addplot coordinates{(0, 0.0000000000)
                                     (1, 0.8823529412)
                                     (2, 0.8750000000) 
                                     (3, 1.0000000000) 
                                     (4, 0.8666666667)
                                     (80, 0.0000000000)}[thick];
            \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

The problem is less pronounced when I don't make my lines thick, but it is still there (and I want thick lines).

1
  • I tried reproducing this, but didn't succeed: For me, the sharp corners are always correctly drawn as bevel joins. Could you post a full minimal example that shows the described behaviour? – Jake Apr 13 '11 at 6:16
12

There are a couple of ways you can avoid this: You can either tell pgfplots to use round corners or beveled corners for all corners by supplying the option line join=round or line join=bevel to the axis or to individual plots, or you can lower the threshold for when the join type changes from mitered to beveled by using miter limit=<value> (10 is the default).

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
    \begin{figure}[ht]
        \begin{tikzpicture}
            \begin{axis}[no markers,grid=major,every axis plot post/.append style={thick}]
                \addplot  coordinates{(0, 0.0) (0, 0.9) (1, 0.9) (2, 1) (3, 0.9) (80, 0)};
                \addplot +[line join=round] coordinates{(0, 0.0) (0, 0.9) (2, 0.9) (3, 1) (4, 0.9) (80, 0)};
                \addplot +[line join=bevel] coordinates{(0, 0.0) (0, 0.9) (3, 0.9) (4, 1) (5, 0.9) (80, 0)};
                \addplot +[miter limit=5] coordinates{(0, 0.0) (0, 0.9) (4, 0.9) (5, 1) (6, 0.9) (80, 0)};
            \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

different ways of joining lines

3
  • If you don't mind, I will copy-paste this example to the pgfplots manual... – Christian Feuersänger Apr 21 '11 at 19:25
  • @christian: By all means, please do! – Jake Apr 22 '11 at 11:01
  • +1 for join=round. This makes my matlab2tikz figures much, much neater. – onewhaleid Mar 10 '15 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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