Heatmap

Heatmap block.

heatmap is a Python package to create interactive heatmaps based on d3js. The heatmap allows interactive clustering where the cluster coloring can be customized. Clusters are colored and within each cluster the color is incremental based on the value. Adjacency matrix must be symetric.

param df:

Input data. The index and column names are used for the row/column naming.

type df:

pd.DataFrame()

param scaler:

Scale the edge-width using the following scaler: ‘zscore’ : Scale values to Z-scores. ‘minmax’ : The sklearn scaler will shrink the distribution between minmax. None : No scaler is used.

type scaler:

str, (default: ‘zscore’)

param color:
Class label to color the clustering.
  • ‘cluster’: colors are based on clustering

  • ‘label’: colors are based on the presence of unique labels

type color:

str or list

param stroke:
Color of the recangle when hovering over a cell.
  • ‘red’

  • ‘black’

type stroke:

String, (default: ‘red’).

param fontsize:

The fontsize of the columns and rows

type fontsize:

int, (default: 10)

param fontsize_mouseover:

The fontsize of the columns and rows with mouse-over

type fontsize_mouseover:

int, (default: 10)

param description:

Description text of the heatmap.

type description:

String, (default: ‘Heatmap description’)

param cluster_params:

Parameters for clustering the data and using the cluster labels to color the heatmap. See references for more information.

type cluster_params:

dict (defaults)

param cmap:
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’, ‘inferno’

type cmap:

String, (default: ‘Set1’)

param title:
Title of the figure.
  • ‘Heatmap’

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].
  • [800, 800]

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)

Examples

>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example data
>>> df = d3.import_example('stormofswords')  # 'energy'
>>> #
>>> # Plot
>>> d3.heatmap(df)
>>> #

Examples

>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example data
>>> df = d3.import_example('energy')
>>> #
>>> # Change cluster parameters
>>> d3.heatmap(df, cluster_params={'evaluate':'dbindex',
>>>                                'metric':'hamming',
>>>                                'linkage':'complete',
>>>                                'normalize': False,
>>>                                'min_clust': 3,
>>>                                'max_clust': 15})
>>> #

Examples

>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example data
>>> df = d3.import_example('bigbang')
>>> #
>>> # Plot and color on label
>>> d3.heatmap(df, color=[1,1,1,2,2,2,3])
>>> d3.node_properties
>>> #
>>> # Plot and specify the hex color
>>> d3.heatmap(df, color=['#FFF000', '#FFF000', '#FFF000', '#000FFF' , '#000FFF', '#000FFF', '#000FFF'])
>>> d3.node_properties

References

Input Data

The input dataset is a DataFrame with three column, source, target and weight.

#                      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]

Charts