我正在使用 pgfplots 绘制多条线,但在一定数量的线之后,无论线条样式如何,它们似乎都会恢复为虚线。
有办法解决这个问题吗?生成该图的代码如下:
\documentclass[10pt]{article}
\usepackage{pgfplots}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}
\addplot+[color=magenta,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
\addplot+[color=magenta,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
\addplot+[color=black,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
\addplot+[color=black,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
\addplot+[color=red,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
\addplot+[color=red,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
mark options
仅影响标记 - 不影响线条样式。\addplot+
向 使用的选项添加选项\addplot
,默认循环显示线条样式、颜色等。因此,只有明确覆盖的选项才会生效。如果您不想附加选项,请使用\addplot[<options>]
。例如:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[color=magenta,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
\addplot[color=magenta,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
\addplot[color=black,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
\addplot[color=black,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
\addplot[color=red,mark=*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
\addplot[color=red,mark=square*,semithick, mark options={solid,fill=markercolor}]
coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};
\end{axis}
\end{tikzpicture}
\end{document}
给出
或者,以更少的麻烦获得相同的结果:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{pgfplots}
\pgfplotsset{%
compat=1.13,
every axis plot/.append style={semithick, mark options={solid,fill=markercolor}}
}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [color=magenta ,mark=*]
coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
\addplot [color=magenta, mark=square*]
coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
\addplot [color=black, mark=*]
coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
\addplot [color=black, mark=square*]
coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
\addplot [color=red, mark=*]
coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
\addplot [color=red, mark=square*]
coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
你已经得到了一个很好的答案,所以这只是一种替代方法,在其他情况下可能会有用。pgfplots
有一个针对每个步骤的样式列表\addplot
。有几个列表可供选择,请参阅第 4.7.7 节循环列表 – 控制线型的选项在手册中,但您也可以定义自己的。如果您有多个图形并且希望所有图形都使用相同的线条样式等,这将特别有用。
要选择cycle list
,请使用cycle list name=<name of list>
。您可以对单个执行此操作axis
,也可以将其放入\pgfplotsset
以将其设置为“全局”。要创建新列表,请使用\pgfplotscreateplotcyclelist{<name>}{<list>}
。在列表中,每行放置一组选项,并以 结束行\\
,如下例所示。
\documentclass[border=4mm]{standalone}
\usepackage{pgfplots}
\definecolor{markercolor}{RGB}{124.9, 255, 160.65}
\pgfplotscreateplotcyclelist{JessePlots}{%
color=magenta,mark=*,semithick, mark options={solid,fill=markercolor}\\
color=magenta,mark=square*,semithick, mark options={solid,fill=markercolor}\\
color=black,mark=*,semithick, mark options={solid,fill=markercolor}\\
color=black,mark=square*,semithick, mark options={solid,fill=markercolor}\\
color=red,mark=*,semithick, mark options={solid,fill=markercolor}\\
color=red,mark=square*,semithick, mark options={solid,fill=markercolor}\\
}
% \pgfplotsset{cycle list name=JessePlots} % for setting the cycle list globally
\begin{document}
\begin{tikzpicture}
\begin{axis}[cycle list name=JessePlots]
\addplot coordinates{(1,1)(2,2)(3,3)(4,4)(5,5)};
\addplot coordinates{(1,2)(2,4)(3,6)(4,8)(5,10)};
\addplot coordinates{(1,3)(2,6)(3,9)(4,12)(5,15)};
\addplot coordinates{(1,4)(2,8)(3,12)(4,16)(5,20)};
\addplot coordinates{(1,5)(2,10)(3,15)(4,20)(5,25)};
\addplot coordinates{(1,6)(2,12)(3,18)(4,24)(5,30)};
\end{axis}
\end{tikzpicture}
\end{document}