0

I'm trying to build an organizational chart, but I need to enter more than one piece of information in the chart and insert people's photos. I will put it below as I did and I would like to know how I can put their photo and title under the names of people. Thanks in advance for the help!


import sqlite3, pandas as pd, networkx as nx

con = sqlite3.connect('people.db')

qry="""
SELECT a1.id, a1.name as a1, a2.name as a2, a1.position as a3
FROM people a1
INNER JOIN people a2 ON a1.manager_id = a2.id
"""

emps=pd.read_sql(qry, con)

emps.rename(
columns={'a2' :'manager', 'a1' :'person', 'a3':'position'},
inplace=True
)

edgelist=emps[['person', 'manager',]]

print(edgelist)

orgchart=nx.from_pandas_edgelist(edgelist, source='manager', target='person')

p=nx.drawing.nx_pydot.to_pydot(orgchart)
p.write_png('orgchart.png')

In each circle I would like to put the name and below the position and photo. And if possible I would like to change the layout from circle to square.

Thank You!

Tried to read de docs, but nothing.

1 Answers1

0

Tried to read de docs, but nothing

Just add attributes to the nodes, and they will be passed "as is" to graphviz.

E.g., if you have a node "Goerge", you can do:

orgchart.nodes['George']['color'] = 'red'
orgchart.nodes['George']['shape'] = 'box'
orgchart.nodes['George']['label'] = 'Georgie boy is a swell guy'

See the Graphviz documentation for node (and edge) attributes.

As for adding images, there's the image attribute (use an absolute path to the image, because pydot switches the working directory to a temporary one), but it's shown as the node background, so use HTML labels instead:

orgchart.nodes['George']['label'] = '<<TABLE><TR><TD>\\N</TD></TR><TR><TD><IMG SRC="/absolute/path/to/george.png"/></TD></TR></TABLE>>'
Niccolo M.
  • 3,363
  • 2
  • 22
  • 39