The D3Blocks library also contains various helper functions to get the data in the right shape for the desired chart.

Export to HTML

Each block can be exported to HTML using the return_html parameter.

# load library
from d3blocks import D3Blocks

# Initialize
d3 = D3Blocks()

# Get data
df = d3.import_example(data='energy')

# Return HTML for Sankey
html = d3.sankey(df, return_html=True)

vec2adjmat

static D3Blocks.vec2adjmat(source, target, weight=None, symmetric=True, aggfunc='sum')

Convert source and target into adjacency matrix.

Parameters:
  • source (list) – The source node.

  • target (list) – The target node.

  • weight (list of int) – The Weights between the source-target values

  • symmetric (bool, optional) – Make the adjacency matrix symmetric with the same number of rows as columns. The default is True.

  • aggfunc (str, optional) –

    Aggregate function in case multiple values exists for the same relationship.
    • ’sum’ (default)

Returns:

adjacency matrix.

Return type:

pd.DataFrame

Examples

>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example
>>> df = d3.import_example('energy')
>>> #
>>> # Convert to adjmat
>>> adjmat = d3.vec2adjmat(df['source'], df['target'], df['weight'])

adjmat2vec

static D3Blocks.adjmat2vec(df, min_weight=1)

Convert adjacency matrix into vector with source and target.

Parameters:
  • adjmat (pd.DataFrame()) – Adjacency matrix.

  • min_weight (float) – edges are returned with a minimum weight.

Returns:

nodes that are connected based on source and target

Return type:

pd.DataFrame()

Examples

>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example
>>> df = d3.import_example('energy')
>>> Convert into adjmat
>>> adjmat = d3.vec2adjmat(df['source'], df['target'], df['weight'])
>>> #
>>> # Convert back to vector
>>> vector = d3.adjmat2vec(adjmat)

Examples

D3Blocks.import_example(data, n=10000, c=300, date_start='17-12-1903 00:00:00', date_stop='17-12-1903 23:59:59', overwrite=False)

Import example dataset from github source.

Import one of the few datasets from github sourcek.

Parameters:
  • data (str) –

    Example datasets:
    • ”movingbubbles”

    • ”random_time”

    • ”timeseries”

    • ”bigbang”

    • ”southern_nebula_internet”

    • ”climate”

    • ”mnist”

    • ”animals”

    Datazets:
    • ”energy”

    • ”stormofswords”

    • ”southern_nebula”

    • ”cancer”

    • ”breast_cancer”

    • ”iris”

    • ”occupancy”

  • n (int, (default: 1000).) – Number of events (samples).

  • c (int, (default: 100).) – Number of classes.

  • date_start (str, (default: None)) –

    Start date.
    • ”17-12-1903 00:00:00” : start date

  • date_stop (str, (default: None)) –

    Stop date.
    • ”17-12-1903 23:59:59” : Stop date

Returns:

Dataset containing mixed features.

Return type:

pd.DataFrame()

Saving Charts

Each d3block contains saving functionality to save your chart to a SVG image. The save functionality can be enabled by setting the ```