6

I have a simple graph in PGFPlots, where the marks of two different plots slightly overlap:

Graph

Around 50 and 100 the graph gets a bit too busy, so I would like to add some whitespace around the marks, where the plot lines are not shown. That would also mean that the plotline would not be visible inside the marks. It should look something like this:

Graph

Is that possible?

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{loglogaxis}[
        width =         \textwidth,
        height =        5cm,
        xtick =         {0.1, 0.5, 1, 5, 10, 50, 100},
        xticklabels =   {0.1, 0.5, 1, 5, 10, 50, 100},
        xtick pos =     left,
        ytick =         {1, 2, 4, 8, 16},
        yticklabels =   {1, 2, 4, 8, 16},
        ytick pos =     left,
        tick align =    outside,
    ]
        \addplot[mark=o] coordinates { (0.1,1) (0.5,1.1) (1,2) (5,4) (10,7) (50,12) (100,16)};
        \addplot[mark=square] coordinates { (0.1,3) (0.5,3.5) (1,5) (5,5.2) (10,8) (50,11) (100,15)};
    \end{loglogaxis}
\end{tikzpicture}
\end{document}
Mikkel R. Lund
  • 203
  • 1
  • 4

1 Answers1

6

You can use the approach from Gap between line and point in pgfplots, like pointintervalbox in gnuplot:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}

\makeatletter
\pgfplotsset{
    discontinuous line/.code={
        \pgfkeysalso{mesh, shorten <=#1, shorten >=#1,
        legend image code/.code={
        \draw [##1, shorten <=0cm] (0cm,0cm) -- (0.3cm,0cm);
        \draw [only marks] plot coordinates {(0.3cm,0cm)};
        \draw [##1, shorten >=0cm] (0.3cm,0cm) -- (0.6cm,0cm);
        }}
        \def\pgfplotsplothandlermesh@VISUALIZE@std@fill@andor@stroke{%
            \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{fill path}%
            \pgfplotsplothandlermesh@definecolor
            \pgfusepath{stroke}
            \pgfplotsplothandlermesh@show@normals@if@configured
        }%
    },
    discontinuous line/.default=1.5mm
}
\makeatother

\begin{tikzpicture}
    \begin{loglogaxis}[
        width =         \textwidth,
        height =        5cm,
        xtick =         {0.1, 0.5, 1, 5, 10, 50, 100},
        xticklabels =   {0.1, 0.5, 1, 5, 10, 50, 100},
        xtick pos =     left,
        ytick =         {1, 2, 4, 8, 16},
        yticklabels =   {1, 2, 4, 8, 16},
        ytick pos =     left,
        tick align =    outside,
        legend entries= {a,b},
        legend pos=     {south east}
    ]
        \addplot[mark=o, discontinuous line, red] coordinates { (0.1,1) (0.5,1.1) (1,2) (5,4) (10,7) (50,12) (100,16)};
        \addplot[mark=square, discontinuous line, black] coordinates { (0.1,3) (0.5,3.5) (1,5) (5,5.2) (10,8) (50,11) (100,15)};
    \end{loglogaxis}
\end{tikzpicture}
\end{document}
Jake
  • 232,450