使用 tikz 和 pgfplots,如何独立于情节线的“样式”来控制点的标记?

使用 tikz 和 pgfplots,如何独立于情节线的“样式”来控制点的标记?

请考虑以下 MWE:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{spy}

\begin{document}
\pgfplotsset{width=10cm}% ,compat=1.18
\begin{tikzpicture}[spy using outlines={circle,magnification=6,connect spies,densely dotted}]
        \pgfplotsset{scale only axis,xmin=1.8, xmax=5}
        \begin{axis}[axis y line*=left,ymin=120, ymax=150,]
            \addplot[thick,dashed,smooth,mark=+,darkgray]
                coordinates{
                    (1.897222, 144)
                    (2.372222, 135)
                    (2.537500, 138)
                    (2.906250, 135)
                    (3.388889, 147)
                    (3.878472, 122)
                    (4.396528, 136)
                    (4.963889, 130)
                };
            \addplot[thick,smooth,mark=*,darkgray]
                coordinates{
                    (1.99, 123)
                    (2.2, 145)
                    (2.75, 134)
                    (3.25, 130)
                    (3.4, 137)
                    (3.8, 128)
                    (4.5, 146)
                    (4.9, 121)
                };
            \coordinate (spyone) at (axis cs:3.4,147);
            \coordinate (spytwo) at (axis cs:4.4,136);
            \coordinate (glassone) at (axis cs:3,125);
            \coordinate (glasstwo) at (axis cs:4.5,125);
        \end{axis}
        \spy[darkgray,size=3cm] on (spyone) in node[fill=white] at (glassone);
        \spy[darkgray,size=3cm] on (spytwo) in node[fill=white] at (glasstwo);
\end{tikzpicture}
\end{document}

它产生以下(近似的,因为下面是一个像素图形和缩小的)输出:

显示该问题的屏幕截图

两个间谍在虚线(thick,dashed,smooth,mark=+,darkgray)上显示标记。通过设置也可以“实现”类似的结果mark=x

无论哪种方式,问题在于标记的绘制继承了线条的虚线样式。

问题:如何使用实心样式绘制标记,同时保留原有的线条样式?

附言:情节扎实,比如第二部,没有问题。既没有问题mark=*也没有问题mark=x

答案1

也许这就是你要找的:我已经添加到选项mark options=solidaddplot

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{spy}

\begin{document}
\pgfplotsset{width=10cm}% ,compat=1.18
\begin{tikzpicture}[spy using outlines={circle,magnification=6,connect spies,densely dotted}]
        \pgfplotsset{scale only axis,xmin=1.8, xmax=5}
        \begin{axis}[axis y line*=left,ymin=120, ymax=150,]
            \addplot[thick,dashed,smooth,mark=+,darkgray, mark options=solid]
                coordinates{
                    (1.897222, 144)
                    (2.372222, 135)
                    (2.537500, 138)
                    (2.906250, 135)
                    (3.388889, 147)
                    (3.878472, 122)
                    (4.396528, 136)
                    (4.963889, 130)
                };
            \addplot[thick,smooth,mark=*,darkgray]
                coordinates{
                    (1.99, 123)
                    (2.2, 145)
                    (2.75, 134)
                    (3.25, 130)
                    (3.4, 137)
                    (3.8, 128)
                    (4.5, 146)
                    (4.9, 121)
                };
            \coordinate (spyone) at (axis cs:3.4,147);
            \coordinate (spytwo) at (axis cs:4.4,136);
            \coordinate (glassone) at (axis cs:3,125);
            \coordinate (glasstwo) at (axis cs:4.5,125);
        \end{axis}
        \spy[darkgray,size=3cm] on (spyone) in node[fill=white] at (glassone);
        \spy[darkgray,size=3cm] on (spytwo) in node[fill=white] at (glasstwo);
\end{tikzpicture}
\end{document}

在此处输入图片描述

如果您愿意的话,您还可以尝试dash phase改变标记的选项。+

相关内容