0

Suppose you have a list of tuples such as the following: enter image description here

The first element of each tuple represents the person ID and the second represents the skill ID. How can I visualize this data with networkx or any other library?

Thank you

2 Answers 2

2

You can draw a bipartite graph with networkx:

import networkx as nx
from matplotlib import pyplot as plt

tuples = [(0, 170),
        (0, 165),
        (1, 165),
        (1, 170),
        (2, 150),
        (2, 170),
        (3, 150),
        (3, 165),
        (4, 170),
        (4, 150)]
left_nodes = [tup[0] for tup in tuples]

G = nx.Graph()
G.add_edges_from(tuples)
pos = nx.bipartite_layout(G, nodes= left_nodes)
node_colors = ["turquoise" if node in left_nodes else "pink" for node in G.nodes]
nx.draw(G,pos=pos, with_labels=True, node_color = node_colors)
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

you can use sankey diagrams like below:

import holoviews as hv
import plotly.graph_objects as go
import plotly.express as pex
import pandas as pd
  
tuples = [(0, 170),
        (0, 165),
        (1, 165),
        (1, 170),
        (2, 150),
        (2, 170),
        (3, 150),
        (3, 165),
        (4, 170),
        (4, 150)]

df = pd.DataFrame.from_records(tuples, columns =['id', 'skill'])
df = df.assign(v=pd.Series([1]*len(tuples)).values)

hv.extension('bokeh')
hv.Sankey(df, kdims=["id","skill"])

output: enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.