circlepacking
- D3Blocks.circlepacking(df, size: str = 'sum', zoom: str = 'click', speed: int = 750, border={'color': '#FFFFFF', 'fill': '#FFFFFF', 'padding': 5, 'width': 1.5}, font: dict = {'color': '#000000', 'outlinecolor': '#FFFFFF', 'size': 20, 'type': 'Source Serif Pro'}, title: str = 'Circlepacking - D3blocks', filepath: str = 'Circlepacking.html', figsize=[900, 1920], showfig: bool = True, overwrite: bool = True, notebook: bool = False, save_button: bool = True, return_html: bool = False, reset_properties: bool = True)
Circlepacking block.
The Circlepacking chart is a visualization to hierarchically show the data as a set of nested circles. For demonstration purposes, the “energy” and “stormofswords” dataset can be used. The javascript code is forked from Mike Bostock and then Pythonized.
- Parameters:
df (pd.DataFrame()) –
- Input data containing the following columns:
’source’, ‘target’, ‘weight’
’level0’, ‘level1’, ‘level2’, ‘weight’
size (str (default: "sum")) –
- Size of the nodes can automatically be set in with:
’sum’ : This is the sum of the weights for the edges
’constant’ : All nodes are set to 1
speed (int (default: 750)) – Speed in ms to zoom in/out
zoom (str (default: "click")) –
- Zooming method.
’click’
’mouseover’
border (dict.) –
- border properties.
{‘color’: ‘#FFFFFF’, ‘width’: 1.5, ‘fill’: ‘#FFFFFF’, “padding”: 2}
border color: color for the circles
width: width for the circles
fill: fill color for the circles
padding: size of the circles
font (dict.) –
- font properties.
{‘size’: 20, ‘type’:’sans-serif’}
title (String, (default: None)) –
- Title of the figure.
’Circlepacking’
filepath (String, (Default: user temp directory)) –
File path to save the output.
Temporarily path: ‘d3blocks.html’
Relative path: ‘./d3blocks.html’
Absolute path: ‘c://temp//d3blocks.html’
None: Return HTML
figsize (tuple) –
- Size of the figure in the browser, [width, height].
[1000, 1200]
[None, None]: Use the screen resolution.
showfig (bool, (default: True)) –
True: Open browser-window.
False: Do not open browser-window.
overwrite (bool, (default: True)) –
True: Overwrite the html in the destination directory.
False: Do not overwrite destination file but show warning instead.
notebook (bool) –
True: Use IPython to show chart in notebook.
False: Do not use IPython.
save_button (bool, (default: True)) –
True: Save button is shown in the HTML to save the image in svg.
False: No save button is shown in the HTML.
return_html (bool, (default: False)) –
True: Return html
False: Nothing is returned
reset_properties (bool, (default: True)) –
True: Reset the node_properties at each run.
False: Use the d3.node_properties()
- 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('animals') >>> df = d3.import_example('energy') >>> # >>> # Plot >>> d3.circlepacking(df) >>> #
Examples
>>> # Load d3blocks >>> from d3blocks import D3Blocks >>> # >>> # Initialize >>> d3 = D3Blocks(chart='Circlepacking', frame=True) >>> # >>> # Import example >>> df = d3.import_example('energy') >>> # >>> # Node properties >>> d3.set_node_properties(df) >>> print(d3.node_properties) >>> # >>> d3.set_edge_properties(df) >>> print(d3.edge_properties) >>> # >>> # Show the chart >>> d3.show()
Examples
>>> # Load d3blocks >>> from d3blocks import D3Blocks >>> # >>> # Initialize >>> d3 = D3Blocks() >>> # >>> # Import example >>> df = d3.import_example('energy') >>> # >>> html = d3.circlepacking(df, >>> speed=1500, >>> zoom='mouseover', >>> filepath='c://temp//circlepacking.html', >>> border={'color': '#FFFFFF', 'width': 1.5, 'fill': '#FFFFFF', "padding": 2}, >>> overwrite=True, >>> ) >>> # >>> # Show the chart >>> d3.show()
Input Data
The input dataset is a DataFrame that is hierarchically ordered from left to right. The number can be 3 levels and the column weight is obligatory.
# source target weight
# 0 Agricultural 'waste' Bio-conversion 124.729
# 1 Bio-conversion Liquid 0.597
# 2 Bio-conversion Losses 26.862
# 3 Bio-conversion Solid 280.322
# 4 Bio-conversion Gas 81.144
# .. ... ... ...
# 63 Thermal generation District heating 79.329
# 64 Tidal Electricity grid 9.452
# 65 UK land based bioenergy Bio-conversion 182.010
# 66 Wave Electricity grid 19.013
# 67 Wind Electricity grid 289.366
# [68 rows x 3 columns]