Füllzeichen und Clip-Markierungen können nicht verwendet werden

Füllzeichen und Clip-Markierungen können nicht verwendet werden

In der groupplotUmgebung muss ich zwei Pfade verwenden fill betweenund einer dieser Pfade hat Markierungen, die sich auf den Achsen befinden. Ich möchte diese Markierungen ausschneiden, aber das verursacht ein Problem mit fill between, da der erste Pfad dann als leer betrachtet wird.

Wie kann ich Markierungen ausschneiden und verwenden fill between?

Unten finden Sie ein MWE. Um das Problem deutlich zu erkennen, können Sie die kommentierte Zeile clip marker paths=true,ein- und ausblenden. Wenn sie nicht kommentiert ist, liegt das Problem hier.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, pgfplots.groupplots}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}

\begin{document}
    \begin{tikzpicture}

    \begin{groupplot}[group style={group size=2 by 1}, scale only axis,
%   clip marker paths=true,
    axis on top=true]

    % Plot main figure (a)
    \nextgroupplot[scale only axis,
    xmin=0,
    xmax=100,
    ymin=0,
    ymax=550]

    \addplot[name path = pathA, color=blue, mark=square*] coordinates {(0,250)(100,450)};
    \path[name path = pathAxis] (axis cs:0,0) -- (axis cs:100,0);
    \addplot [gray!30] fill between[of = pathA and pathAxis, soft clip = {domain=20:50}];

    \nextgroupplot[scale only axis, restrict y to domain=190:240]

    \end{groupplot}

    \end{tikzpicture}
\end{document}

Antwort1

Dies ist nur eine Problemumgehung. Sie fügen den Plot zweimal hinzu, einmal unsichtbar, um etwas zu haben, das zum Füllen verwendet werden kann, und einmal „in Wirklichkeit“. (Ich habe ein bisschen mit Clips usw. experimentiert, aber nichts von dem, was dabei herauskam, war wirklich eleganter als diese Problemumgehung, also poste ich sie. Natürlich hoffe ich, dass es eine elegantere Lösung gibt.)

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, pgfplots.groupplots}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}

\begin{document}
    \begin{tikzpicture}

    \begin{groupplot}[group style={group size=2 by 1}, scale only axis,
    axis on top=true]

    % Plot main figure (a)
    \nextgroupplot[scale only axis,clip marker paths=true,
    xmin=0,
    xmax=100,
    ymin=0,
    ymax=550]

    \addplot[color=blue, mark=square*] coordinates {(0,250)(100,450)};
    \addplot[name path = pathA,draw=none,no marks,forget plot] coordinates {(0,250)(100,450)};
    \path[name path = pathAxis] (axis cs:0,0) -- (axis cs:100,0);
    \addplot [gray!30] fill between[of = pathA and pathAxis, soft clip = {domain=20:50}];

    \nextgroupplot[scale only axis, restrict y to domain=190:240]
    \end{groupplot}

    \end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen