In order to construct a directed network graph, Plotly's current approach seems to be using annotations. This works when there are few edges and one can manually populate each one through the figure layout, e.g., this example.
But if I'm creating a much more complicated graph, is there a good way to iteratively define the arrow coordinates for all the edges (I can only think of constructing a string and then use eval()
, although I know it's bad practice)? (edit: it seems this approach of concatenating iteratively generated dict()
definition strings doesn't work -- worked only for one dict()
definition)
Edit: adding a code snippet to better illustrate the scenario (with the eval()
line commented out for comparison):
import plotly.offline as py
import plotly.graph_objs as go
trace = go.Scatter(
x=[1, 2, 2, 1],
y=[3, 4, 3, 4],
mode='markers',
marker=dict(size=[100, 100, 100, 100])
)
fig = go.Figure(
data=[trace],
layout=go.Layout(
annotations = [
dict(
ax=1, ay=3, axref='x', ayref='y',
x=2, y=4, xref='x', yref='y'
),
# eval("dict(ax=2, ay=3, axref='x', ayref='y', x=1, y=4, xref='x', yref='y')")
]
)
)
py.plot(fig)
I'm open to try other visualization packages as well, if there is a good way in doing this under Bokeh or others.