🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Filled Chord Diagram in Python

Hi there,

I am trying to plot a chord diagram. I follow plotly’s example on https://plot.ly/python/filled-chord-diagram/.

However, when I let the example run in a jupyter notebook I get the error:

AttributeError: ‘tuple’ object has no attribute ‘append’

everytime the layout shape colors are set, e.g.
layout[‘shapes’].append(make_self_rel(l, ‘rgb(175,175,175)’ , ideo_colors[k], radius=radii_sribb[k]))

I am wondering whether plotly switched to representing layout.shapes as a tuple instead of a list.

Can anybody help me out how to work work around it?

I found a fix. The following works: Instead of directly appending to layout[‘shapes’] (in each for loop), one can simply initialize a list, e.g.

layout_shapes_list = []

then in each for loop append data to the list, i.e.

layout_shapes_list.append(make_self_rel(l, ‘rgb(175,175,175)’ ,ideo_colors[k], radius=radii_sribb[k]))
layout_shapes_list.append(make_ribbon(l, r, ‘rgb(175,175,175)’ , ribbon_color[k][j]))
layout_shapes_list.append(make_ideo_shape(path,‘rgb(150,150,150)’ , ideo_colors[k]))

and at the very end set the layout[‘shapes’]

layout[‘shapes’] = layout_shapes_list

1 Like

@sebo1, Yes, you are right! That notebook was posted 3 years ago. Here http://nbviewer.jupyter.org/github/empet/Plotly-plots/blob/master/Chord-diagram.ipynb?flush_cache=true I updated it to work with Python 3.6.4 and Plotly 3.3+ (I wrote all strings as f-strings and this simplifies very much the svg paths description). Also I defined the layout as a dict, not as an instance of go.Layout, and so layout['shapes'].append() still works.

1 Like

In case anyone who didn’t solve this problem. I found someone who collected the code in the plotly’s example of filled-chord-diagram and rearranged the code.
It works fine. The author published it on Github. Here’s the link: https://gist.github.com/rmarren1/d593535900f0da0ad52e8a160f3767bd
The input format is a Dataframe with a column of the labels.

1 Like

Thanks @yoursugar for pointing out the file chord.py I created the notebook 5 years ago as a tutorial. At that time no Python plotting library provided methods to define a chord diagram That’s why I explained each step and did not save the involved functions in a module.

1 Like