microsoft / vivainsights-py

Python package for Analyzing and Visualizing data from Viva Insights
https://microsoft.github.io/vivainsights-py/
Other
13 stars 2 forks source link

No colour coding available in P2P or G2G graphs. #16

Closed adityatyagi160698 closed 11 months ago

adityatyagi160698 commented 11 months ago

I can not get coloured graphs as output in P2P or G2G. I tried running both the sample data codes as well as attached in the screenshot but wasn't able to get the desired output. I then tried another sample code to check the pycairo package and it worked but the viva code is not giving coloured output graphs.

import igraph as ig import matplotlib.pyplot as plt

Create a graph

g = ig.Graph() g.add_vertices(3) g.add_edges([(0, 1), (1, 2)])

Set vertex attributes

g.vs['label'] = ['A', 'B', 'C'] g.vs['color'] = ['red', 'green', 'blue']

Set edge attributes

g.es['width'] = [1, 2]

Create a layout

layout = g.layout('kk')

Plot the graph using matplotlib

ig.plot(g, layout=layout, target='temp.png') img = plt.imread('temp.png') plt.imshow(img) plt.axis('off') plt.show()

P2P Sample matplotlib graph g2g

martinctc commented 11 months ago

Thanks @adityatyagi160698. Through some troubleshooting, it looks like that the vertices are simply scaled too small by default. We will try to add a scaling parameter so that the vertices can increase in size. In the meantime, the following workarounds can be used to create network visuals:

For group-to-group:

import vivainsights as vi
import igraph as ig
import matplotlib.pyplot as plt

g = vi.network_g2g(
    data = vi.load_g2g_data(), # change dataset here
    primary = "PrimaryCollaborator_Organization",
    secondary = "SecondaryCollaborator_Organization",
    metric = "Meeting_Count", # update metric
    return_type = "network"
    )

g = g.simplify()
fig, ax = plt.subplots(figsize=(8, 8))

g.vs["org_size"] = [x*50 for x in g.vs["org_size"]] # scale the size of the nodes

ig.plot(
    g,
    layout=g.layout("mds"),
    target=ax,
    vertex_color="blue", # set vertex color here
    vertex_label=g.vs["name"],
    vertex_frame_width=1,
    vertex_size=g.vs["org_size"],
    edge_alpha=0.5,
    edge_color="grey"
)

plt.show()

For person-to-person:

import vivainsights as vi
import igraph as ig
import matplotlib.pyplot as plt

g_p2p = vi.network_p2p(
    data = vi.p2p_data_sim(),
    return_type = "network"
    )

g = g_p2p.simplify()
fig, ax = plt.subplots(figsize=(8, 8))

g.vs["node_size"] = [x*50 for x in g.vs["node_size"]] # scale the size of the nodes

ig.plot(
    g,
    layout = g.layout("mds"),
    target=ax,
    vertex_label = None,
    vertex_size = g.vs["node_size"],
    vertex_color = "blue",
    edge_arrow_mode = "0",
    edge_arrow_size=0, 
    edge_color = "#adadad",
) 

plt.show()
adityatyagi160698 commented 11 months ago

Thank you so much for your help Martin!!