Chord
Chord block.
A chord represents flows or connections between several entities or nodes. Each entity is represented by a fragment on the outer part of the circular layout. Then, arcs are drawn between each entity. The size of the arc is proportional to the importance of the flow.
- param df:
- Input data containing the following columns:
“source”
“target”
“weight”
“color” (optional)
“opacity” (optional)
- type df:
pd.DataFrame()
- param color:
- Link colors in Hex notation. Should be the same size as input DataFrame.
“source” : Color edges/links similar to that of source-color node.
“target” : Color edges/links similar to that of target-color node.
“source-target” : Color edges/link based on unique source-target edges using the colormap.
“#ffffff” : All links have the same hex color.
[“#000000”, “#ffffff”,…] : Define per link.
- type color:
(default: ‘source’)
- param opacity:
- Link Opacity. Should be the same size as input DataFrame.
‘source’: Opacity of edges/links similar to that of source-opacity node.
‘target’: Opacity of edges/links similar to that of target-opacity node.
0.8: All links have the same opacity.
[0.1, 0.75,…]: Set opacity per edge/link.
- type opacity:
(default: ‘source’)
- param ordering:
- Sort the labels.
‘ascending’
‘descending’
‘’: Do not sort
[‘label1’, ‘label2’, ‘label3’]: Custom sort. Note that all labels shoul be included only once for the best result.
- type ordering:
(default: ‘ascending’)
- param fontsize:
The Fontsize.
- type fontsize:
int, (default: 8)
- param arrowhead:
- The head of the arrow.
-1: No arrow
10: default
50: The larger the more pointy the arrow becomes
- type arrowhead:
int, (default: 10)
- param cmap:
- colormap is only used in case color=None. All colors can be reversed with ‘_r’, e.g. ‘binary’ to ‘binary_r’
‘tab20c’, ‘Set1’, ‘Set2’, ‘rainbow’, ‘bwr’, ‘binary’, ‘seismic’, ‘Blues’, ‘Reds’, ‘Pastel1’, ‘Paired’, ‘twilight’, ‘hsv’
- type cmap:
String, (default: ‘tab20’)
- param title:
- Title of the figure.
‘Chord’
- type title:
String, (default: None)
- param filepath:
- File path to save the output.
Temporarily path: ‘d3blocks.html’
Relative path: ‘./d3blocks.html’
Absolute path: ‘c://temp//d3blocks.html’
None: Return HTML
- type filepath:
String, (Default: user temp directory)
- param figsize:
- Size of the figure in the browser, [width, height].
[900, 900]
- type figsize:
tuple
- param showfig:
True: Open browser-window.
False: Do not open browser-window.
- type showfig:
bool, (default: True)
- param overwrite:
True: Overwrite the html in the destination directory.
False: Do not overwrite destination file but show warning instead.
- type overwrite:
bool, (default: True)
- param notebook:
True: Use IPython to show chart in notebook.
False: Do not use IPython.
- type notebook:
bool
- param save_button:
True: Save button is shown in the HTML to save the image in svg.
False: No save button is shown in the HTML.
- type save_button:
bool, (default: True)
- param reset_properties:
True: Reset the node_properties at each run.
False: Use the d3.node_properties()
- type reset_properties:
bool, (default: True)
- returns:
d3.node_properties (DataFrame of dictionary) – Contains properties of the unique input label/nodes/samples.
d3.edge_properties (DataFrame of dictionary) – Contains properties of the unique input edges/links.
d3.config (dictionary) – Contains configuration properties.
Examples
>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example data
>>> df = d3.import_example('energy')
>>> #
>>> # Plot
>>> d3.chord(df)
>>> #
Examples
>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks(chart='Chord', frame=False)
>>> #
>>> # Import example
>>> df = d3.import_example('energy')
>>> #
>>> # Node properties
>>> d3.set_node_properties(df, opacity=0.2, cmap='tab20')
>>> d3.set_edge_properties(df, color='source', opacity='source')
>>> #
>>> # Show the chart
>>> d3.show()
>>> #
>>> # Make some edits to highlight the Nuclear node
>>> # d3.node_properties
>>> d3.node_properties.get('Nuclear')['color']='#ff0000'
>>> d3.node_properties.get('Nuclear')['opacity']=1
>>> # Show the chart
>>> #
>>> d3.show()
>>> # Make edits to highlight the Nuclear Edge
>>> d3.edge_properties.loc[(d3.edge_properties['source'] == 'Nuclear') & (d3.edge_properties['target'] == 'Thermal generation'), 'color'] = '#ff0000'
>>> d3.edge_properties.loc[(d3.edge_properties['source'] == 'Nuclear') & (d3.edge_properties['target'] == 'Thermal generation'), 'opacity'] = 0.8
>>> d3.edge_properties.loc[(d3.edge_properties['source'] == 'Nuclear') & (d3.edge_properties['target'] == 'Thermal generation'), 'weight'] = 1000
>>> #
>>> # Show the chart
>>> d3.show()
Examples
>>> # Change the order of the labels.
>>> #
>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Import example
>>> df = d3.import_example('energy')
>>> #
>>> # Custom order of the labels
>>> d3.chord(df, ordering=np.sort(np.unique(df['source'].values)))
>>> #
>>> # Sort Ascending
>>> d3.chord(df, ordering='ascending')
>>> #
>>> # Sort Descending
>>> d3.chord(df, ordering='descending')
>>> #
>>> # Do not sort
>>> d3.chord(df, ordering='')
References
Input Data
The input dataset is a DataFrame with three column, source, target and weight.
# source target weight
# 0 Aemon Grenn 5
# 1 Aemon Samwell 31
# 2 Aerys Jaime 18
# 3 Aerys Robert 6
# 4 Aerys Tyrion 5
# .. ... ... ...
# 347 Walder Petyr 6
# 348 Walder Roslin 6
# 349 Walton Jaime 10
# 350 Ygritte Qhorin 7
# 351 Ygritte Rattleshirt 9
# [352 rows x 3 columns]