# how to draw bipartite graph with label?

by user2869180   Last Updated July 12, 2019 01:23 AM

I want to draw a bipartite graph like the following:

I tried the following code:

\definecolor{myblue}{RGB}{80,80,160}
\definecolor{mygreen}{RGB}{80,160,80}

\begin{tikzpicture}[thick,
every node/.style={draw,circle},
fsnode/.style={fill=myblue},
ssnode/.style={fill=mygreen},
every fit/.style={rounded corners,rectangle,draw,inner sep=-2pt,text width=2cm, dashed},
->,shorten >= 3pt,shorten <= 3pt
]

% the vertices of U
\begin{scope}[start chain=going below,node distance=7mm]
\foreach \i in {1,2}
\node[fsnode,on chain] (f\i)  {$v_{\i}$};
\end{scope}

% the vertices of V
\begin{scope}[xshift=4cm,yshift=0.6cm,start chain=going below,node distance=7mm]
\foreach \i in {6,7,8,9}
\node[ssnode,on chain] (s\i)  {$v_{\i}$};
\end{scope}

% the set U
\node [myblue,fit=(f1) (f2),label=above:$G^{P}$] {};
% the set V
\node [mygreen,fit=(s6) (s9),label=above:$G^{Q}$] {};

% the edges
\draw (f1) -- (s6);
\draw (f1) -- (s7);
\draw (f2) -- (s6);
\draw (f2) -- (s7);
\end{tikzpicture}


It not give the same. In addition, how can I add a weight to this bipartite graph? The idea that I need also to add another graph on the right of the arrow. How can aggregate all?

Tags :

## Related Questions

Updated May 12, 2018 12:23 PM

Updated April 13, 2019 13:23 PM

Updated December 20, 2018 03:23 AM

Updated December 17, 2018 22:23 PM

Updated December 18, 2018 02:23 AM