我想为我的pgfplots
图表创建一个条件样式,该样式将根据输入值使用这种或那种基本样式。
这是一个取决于 numplots 值的条件样式的示例,问题是我不知道如何实现条件,因为命令\numplots
无法识别\ifthenelse{...}
。 有可能解决这个问题吗?
\documentclass{standalone}
\usepackage{pgfplots, ifthen}
\pgfplotsset{
MyList-1/.style={
cycle list={
red, mark=*\\
},
},
MyList-2/.style={
cycle list={
blue, mark=*\\%
red, mark=*\\%
},
},
MyList-3/.style={
cycle list={
green, mark=*\\%
red, mark=*\\%
blue, mark=*\\%
},
},
MyList-4/.style={
cycle list={
red, mark=*\\%
black, mark=*\\%
green, mark=*\\%
purple, mark=*\\%
},
},
MyList-5/.style={
cycle multiindex* list={
blue\\%
yellow\\%
orange\\%
red\\%
green\\%
\nextlist
mark=*\\
mark=square*\\
},
},
MyList-6/.style={
cycle multiindex* list={
teal\\%
violet\\%
red\\%
magenta\\%
blue\\%
brown\\%
\nextlist
mark=*\\
mark=square*\\
},
},
MyListChoice/.code={%
\ifthenelse{\equal{\numplots}{1}}{MyList-1}{
\ifthenelse{\equal{\numplots}{1}}{MyList-2}{
\ifthenelse{\equal{\numplots}{1}}{MyList-3}{
\ifthenelse{\equal{\numplots}{1}}{MyList-4}{
\ifthenelse{\equal{\numplots}{1}}{MyList-5}{
\ifthenelse{\equal{\numplots}{1}}{MyList-6}{
}}}}}}
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[MyListChoice]
\addplot coordinates {(0,0)(1,1)};
\addplot coordinates {(1,0)(2,1)};
\addplot coordinates {(2,0)(3,1)};
\addplot coordinates {(3,0)(4,1)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我认为您正在寻找/.is choice
密钥处理程序。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{MyList/.is choice,
MyList/1/.style={
cycle list={
red, mark=*\\
},
},
MyList/2/.style={
cycle list={
blue, mark=*\\%
red, mark=*\\%
},
},
MyList/3/.style={
cycle list={
green, mark=*\\%
red, mark=*\\%
blue, mark=*\\%
},
},
MyList/4/.style={
cycle list={
red, mark=*\\%
black, mark=*\\%
green, mark=*\\%
purple, mark=*\\%
},
},
MyList/5/.style={
cycle multiindex* list={
blue\\%
yellow\\%
orange\\%
red\\%
green\\%
\nextlist
mark=*\\
mark=square*\\
},
},
MyList/6/.style={
cycle multiindex* list={
teal\\%
violet\\%
red\\%
magenta\\%
blue\\%
brown\\%
\nextlist
mark=*\\
mark=square*\\
},
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[MyList=2]
\addplot coordinates {(0,0)(1,1)};
\addplot coordinates {(1,0)(2,1)};
\addplot coordinates {(2,0)(3,1)};
\addplot coordinates {(3,0)(4,1)};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[MyList=4]
\addplot coordinates {(0,0)(1,1)};
\addplot coordinates {(1,0)(2,1)};
\addplot coordinates {(2,0)(3,1)};
\addplot coordinates {(3,0)(4,1)};
\end{axis}
\end{tikzpicture}
\end{document}