在绘图标记周围添加空白

在绘图标记周围添加空白

我在 PGFPlots 中有一个简单的图表,其中两个不同图的标记略有重叠:

图形

在 50 和 100 左右,图表会变得有点太忙,所以我想在标记周围添加一些空白,这些标记不会显示情节线。这也意味着情节线在标记内不可见。它应该看起来像这样:

图形

那可能吗?

\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}

答案1

您可以使用以下方法pgfplots 中线和点之间的间隙,类似于 gnuplot 中的 pointintervalbox

\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}

相关内容