Я использовал следующий код для создания интерактивного графика, эта работа еще не завершена, но я хотел опубликовать ее, чтобы люди могли использовать ее в случае необходимости.
import pandas as pd
import dash
import dash_html_components as html
import dash_cytoscape as cyto
from matplotlib import colors as mcolors
from itertools import zip_longest
from ast import literal_eval
colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
# Sort colors by hue, saturation, value and name.
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
for name, color in colors.items())
sorted_names = [name for hsv, name in by_hsv]
app = dash.Dash(__name__)
# colors = ['red', 'blue', 'green', 'yellow', 'pink']
# stylesheet for the web page generated
default_stylesheet = [
{
"selector": 'node',
'style': {
"opacity": 0.9,
'height': 15,
'width': 15,
'background-color': '#222222',
'label': 'data(label)'
}
},
{
"selector": 'edge',
'style': {
"curve-style": "bezier",
"opacity": 0.3,
'width': 2
}
},
*[{
"selector": '.' + color,
'style': {'line-color': color}
} for color in sorted_names]
]
# Example data for illustration
# My actual data was in the excel file with two columns Managers and Person
managers = ['Person A',
'Person A',
'Person A',
'Person A',
'Person A',
'Person A',
'Person B',
'Person B',
'Person B',
'Person B',
'Person B',
'Person B',
'Person C',
'Person C',
'Person C',
'Person C',
'Person C',
'Person C',
'Person V',
'Person V',
'Person V',
'Person V',
'Person V']
person = ['Person D',
'Person E',
'Person F',
'Person G',
'Person H',
'Person I',
'Person J',
'Person K',
'Person L',
'Person M',
'Person N',
'Person O',
'Person P',
'Person Q',
'Person R',
'Person S',
'Person T',
'Person U',
'Person A',
'Person W',
'Person X',
'Person B',
'Person C']
# Creating a dataframe with the illustration data
df = pd.DataFrame(list(zip(person, managers)), columns=['Person', 'Manager'])
# Giving colors to each managers in the dataframe
df['colors'] = df['Manager'].map(dict(zip_longest(list(set(managers)), sorted_names)))
# Creating the nodes within the dataframe
df['y_node_target'] = "{\"data\": {\"id\": \"" + df['Person'] + "\", \"label\":\""+df['Person']+"\"}, \"classes\": \"" + df['colors'] + "\"}"
df['y_node'] = "{\"data\": {\"id\": \"" + df['Manager'] + "\", \"label\":\""+df['Manager']+"\"}, \"classes\": \"" + df['colors'] + "\"}"
nodes = list(set(pd.concat([df['y_node'], df['y_node_target']]).to_list()))
df['Edges'] = "{\'data\': {\'source\':\"" + df['Manager'] + "\", \'target\': \"" + df[
'Person'] + "\"},\'classes\': \"" + df['colors'] + "\"}"
# Converting the strings to dictionaries and assigning them to variables
edges = list(set(df['Edges'].astype(str).to_list()))
edges = list(map(literal_eval, edges))
nodes = list(map(literal_eval, nodes))
app.layout = html.Div([
cyto.Cytoscape(
id='cytoscape',
elements=edges + nodes,
stylesheet=default_stylesheet,
layout={
'name': 'breadthfirst'
},
style={'height': '95vh', 'width': '100%'}
)
])
if __name__ == '__main__':
app.run_server(debug=True)
Вывод был веб-страница -
![enter image description here](https://i.stack.imgur.com/BA06r.png)