如何绘制具有特定节点颜色的二分图?

如何绘制具有特定节点颜色的二分图?

我的代码:

    \documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,positioning,quotes}
\begin{document}
\definecolor{myblue}{RGB}{80,80,160}
\definecolor{mygreen}{RGB}{80,160,80}

\begin{tikzpicture}[thick,amat/.style={matrix of nodes,nodes in empty cells,
  row sep=1em,draw,dashed,rounded corners,
  nodes={draw,solid,circle,execute at begin node={$v_{\the\pgfmatrixcurrentrow}$}}},
  amat2/.style={matrix of nodes,nodes in empty cells,
  row sep=1em,draw,dashed,rounded corners,
  nodes={draw,solid,circle,execute at begin node={$u_{\the\pgfmatrixcurrentrow}$}}},
  fsnode/.style={fill=myblue},
  ssnode/.style={fill=mygreen}]

 \matrix[amat,nodes=fsnode,label=above:$V^{1}$] (mat1) {\\
 };

 \matrix[amat2,right=2cm of mat1,nodes=ssnode,label=above:$V^{2}$] (mat2) {\\
 \\ 
 \\};

 \draw  (mat1-1-1) edge["$1$"] (mat2-1-1)
  (mat1-1-1) edge["$2$"] (mat2-2-1);

  \draw  (mat1-1-1) edge["$3$"] (mat2-3-1);
  \end{tikzpicture}
\end{document}

我得到两组V^1V^2:1. 我需要将边值最大的节点(即我的代码中权重为 3 的边)的名称V^2设为红色。

答案1

您可以red通过添加来填充任何节点|[fill=red]|。我希望正确解释您的指示。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,positioning,quotes}
\begin{document}
\definecolor{myblue}{RGB}{80,80,160}
\definecolor{mygreen}{RGB}{80,160,80}

\begin{tikzpicture}[thick,amat/.style={matrix of nodes,nodes in empty cells,
  row sep=1em,draw,dashed,rounded corners,
  nodes={draw,solid,circle,execute at begin node={$v_{\the\pgfmatrixcurrentrow}$}}},
  amat2/.style={matrix of nodes,nodes in empty cells,
  row sep=1em,draw,dashed,rounded corners,
  nodes={draw,solid,circle,execute at begin node={$u_{\the\pgfmatrixcurrentrow}$}}},
  fsnode/.style={fill=myblue},
  ssnode/.style={fill=mygreen}]

 \matrix[amat,nodes=fsnode,label=above:$V^{1}$] (mat1) {
 \\
 };

 \matrix[amat2,right=2cm of mat1,nodes=ssnode,label=above:$V^{2}$] (mat2) {\\
 \\ 
 |[fill=red]|\\};

 \draw  (mat1-1-1) edge["$1$"] (mat2-1-1)
  (mat1-1-1) edge["$2$"] (mat2-2-1);

  \draw  (mat1-1-1) edge["$3$"] (mat2-3-1);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容