1

I am attempting to build a dynamic graph in python using networkX. I've got some code to build a static graph. I'm looking for some advice as to how to alter it for dynamic graphing to improve the visualization, maybe using networkx d3 or plotly. The context is to graph a conversation.

nx.draw_networkx(speech, pos=nx.spring_layout(speech))
plt.draw()
static_images_dir = "./static/images"
if not os.path.exists(static_images_dir):
    os.makedirs(static_images_dir)
plt.savefig(os.path.join(static_images_dir, "speech.png"))
#plt.show()
plt.close()
return speech 
2

1 Answer 1

2

I am not sure if that's what you mean by dynamic, but maybe something like this?

import networkx as nx
import numpy as np
import matplotlib.pylab as plt
import hvplot.networkx as hvnx
import holoviews as hv
from bokeh.models import HoverTool
hv.extension('bokeh')

A = np.matrix([[0,1,1,0,0],[1,0,1,0,0],[1,1,0,1,1],[0,0,1,0,1],[0,0,1,1,0]])
G = nx.from_numpy_matrix(A)
pos = nx.spring_layout(G)

nx.draw_networkx(G, pos, node_color='lightgray')
plt.show()

hvnx.draw(G, pos, node_color='lightgray').opts(tools=[HoverTool(tooltips=[('index', '@index_hover')])])

Which produces the output:

Normal static graph

Dynamic graph you can interact with

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

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.