答案1
这不提供完整的代码,但提供了提示,以便您可以缩短代码。您可以pic
对每个点组使用这样的代码。
\documentclass[tikz]{standalone}
\tikzset{
dotcirc/.style={circle,inner sep=2pt,draw,fill=#1},
pics/tripdots/.style args={#1/#2-#3/#4-#5/#6,name=#7}{
code={
\begin{scope}[local bounding box=#7]
\draw (-1.2,0)--(1.2,0);
\draw (0,0.2)--(0,-.2);
\path (-1,0) node[dotcirc=#1] (#2) {};
\path (0,0) node[dotcirc=#3] (#4) {};
\path (1,0) node[dotcirc=#5] (#6) {};
\end{scope}
}
}
}
\begin{document}
\begin{tikzpicture}
\pic at (0,0) {tripdots={red/ra-yellow/ya-green/ga,name=a}};
\draw[<-] (a) -- ++(.5,1) node[above] {\scalebox{0.5}{Traffic lights}};
\draw[<-] (ra) -- ++ (.5,-1) node[below] {\scalebox{0.5}{A colored circle}};
\end{tikzpicture}
\end{document}