![使用 tikz 和 pgfplots,如何独立于情节线的“样式”来控制点的标记?](https://linux22.com/image/464528/%E4%BD%BF%E7%94%A8%20tikz%20%E5%92%8C%20pgfplots%EF%BC%8C%E5%A6%82%E4%BD%95%E7%8B%AC%E7%AB%8B%E4%BA%8E%E6%83%85%E8%8A%82%E7%BA%BF%E7%9A%84%E2%80%9C%E6%A0%B7%E5%BC%8F%E2%80%9D%E6%9D%A5%E6%8E%A7%E5%88%B6%E7%82%B9%E7%9A%84%E6%A0%87%E8%AE%B0%EF%BC%9F.png)
请考虑以下 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=solid
中addplot
\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
改变标记的选项。+