Chord Graph Tutorial Error

Hi, I’m following this tutorial to create a chord graph.
I replaced

import plotly.plotly as py

with

from chart_studio import plotly as py

since plotly.plotly is deprecated.
The actual problem is that even though I followed literally the guide, an error occurs that tells me a map object is not subscriptable (that is true).
In this case, the Weights variable is subscripted inside the for loop (line starting with >>>)

Weights= map(int, G.es["weights"])
...
for j, e in enumerate(E):
    ...
    pts=BezierCv(b, nr=5)
>>> text=V[e[0]]['label']+' to '+V[e[1]]['label']+' '+str(Weights[j])+' pts'
    mark=deCasteljau(b,0.9)
    ...

Probably the tutorial used python2, but in python3 maps are not subscriptable anymore. The problem is that I don’t really know how to define Weights in python3 in order to obtain the same script behavior.

Do you know any solution?
Or is there a newer guide on this same topic?

@Mirk0_98 The code for chord graph was written for Python 2, in 2015. You must update it to work with Python 3, and the latest Plotly version.

Yes, I noticed it was for python2 that’s why I’m looking for an alternative way to use the map() function since it’s different between the 2 versions. There is no guide for v4 as stated here.
My question is if anyone of you knows a workaround for this problem.

@Mirk0_98

I forgot that I updated the code for this type of graph, three years ago.
You can download this notebook https://github.com/empet/Plotly-plots/blob/master/EuroVision-Circular-Graph.ipynb and the gml file, Eurovision15.gml https://github.com/empet/Plotly-plots/blob/master/Data/Eurovision15.gml.
Comment out import plotly as py, and eventually replace FigureWidget by Figure. I’ve just downloaded this notebook and run it. It works perfectly.

2 Likes

Thanks, it works for me too. Now I’m going to study the code to make it actually work for my dataset. :grin: