subrela.plot.bokeh.draw_dendrogram function

subrela.plot.bokeh.draw_dendrogram(fig, leaf_data, tree_data, cut_data, palette=None, orientation='vertical', tree_kws=None, cut_kws=None)[source]

Draw a dendrogram.

Parameters
Returns

  • tree_line (bokeh.models.renderers.GlyphRenderer) – Renderer for tree lines.

  • cut_line (bokeh.models.renderers.GlyphRenderer) – Renderer for cut lines.

Raises

ValueError – If tree_kws contains key 'xs', 'ys', and 'source'. If cut_kws contains key 'xs', 'ys', and 'source'.

Notes

A default color of a tree is tree_kws['line_color']. If it does not exist, tree_kws['color'] is used. If both do not exist, palette[0] is used and group colors are selected from palette[1:].

If neither key 'line_color' nor key 'color' is in cut_kws, 'black' is set to 'line_color'. The default value for cut_kws['line_dash'] is 'dashed'.

Examples

import numpy
import bokeh.plotting
import bokeh.io
from subrela.clustering import get_clusters
from subrela.plot import get_dendrogram_data
from subrela.plot.bokeh import draw_dendrogram

X = numpy.array([[0, -5, -5, 6, 6], [0, -1, 1, -2, 2]])

Z = get_clusters(X)
leaf_data, _, tree_data, cut_data = get_dendrogram_data(
    Z, groups=[0, 5, 6])

fig = bokeh.plotting.Figure(plot_width=300, plot_height=300)
draw_dendrogram(fig, leaf_data, tree_data, cut_data)
bokeh.io.show(fig)

Change colors:

import numpy
import bokeh.plotting
import bokeh.io
from subrela.clustering import get_clusters
from subrela.plot import get_dendrogram_data
from subrela.plot.bokeh import draw_dendrogram

X = numpy.array([[0, -5, -5, 6, 6], [0, -1, 1, -2, 2]])

Z = get_clusters(X)
leaf_data, _, tree_data, cut_data = get_dendrogram_data(
    Z, groups=[0, 5, 6])

fig = bokeh.plotting.Figure(plot_width=300, plot_height=300)
draw_dendrogram(fig, leaf_data, tree_data, cut_data,
                palette=['magenta', 'cyan'])
bokeh.io.show(fig)

Draw horizontally:

import numpy
import bokeh.plotting
import bokeh.io
from subrela.clustering import get_clusters
from subrela.plot import get_dendrogram_data
from subrela.plot.bokeh import draw_dendrogram

X = numpy.array([[0, -5, -5, 6, 6], [0, -1, 1, -2, 2]])

Z = get_clusters(X)
leaf_data, _, tree_data, cut_data = get_dendrogram_data(
    Z, groups=[0, 5, 6])

fig = bokeh.plotting.Figure(plot_width=300, plot_height=300)
draw_dendrogram(fig, leaf_data, tree_data, cut_data,
                orientation='horizontal')
bokeh.io.show(fig)