subrela.plot.bokeh.draw_trace function

subrela.plot.bokeh.draw_trace(fig, trace_data, orientation='vertical', kws=None)[source]

Draw trace lines.

Parameters
  • fig (bokeh.plotting.figure.Figure) – Figure on which trace lines are drawn.

  • trace_data (pandas.DataFrame) – Data of trace lines returned by subrela.plot.get_trace_data function.

  • orientation ({'vertical', 'horizontal'}, optional) – Orientation of a tree. If 'vertical', the height direction of a tree corresponds to the y axis. If 'horizontal', it corresponds to the x axis.

  • kws (dict or None, optional) – Keyword arguments passed to bokeh.plotting.figure.Figure.multi_line method.

Returns

line (bokeh.models.renderers.GlyphRenderer) – Renderer for trace lines.

Notes

If neither key 'line_color' nor key 'color' is in kws, 'black' is set to 'line_color'. The default value for kws['line_width'] is 2.

Examples

import numpy
import bokeh.plotting
import bokeh.layouts
import bokeh.io
from subrela.records import from_arrays
from subrela.clustering import get_clusters
from subrela.analysis import (get_strong_relevance_scores,
                              get_weak_relevance_scores)
from subrela.plot import get_dendrogram_data, get_trace_data
from subrela.plot.bokeh import draw_dendrogram, draw_trace

scores = from_arrays([[False, False, False, True, True],
                      [True, False, False, True, True],
                      [False, True, False, True, True],
                      [True, True, False, True, True],
                      [False, False, True, True, True],
                      [True, False, True, True, True],
                      [False, True, True, True, True],
                      [True, True, True, True, True]],
                     [0.7, 0.7, 0.8, 0.8, 0.9, 0.9, 1., 1.])
X = numpy.array([[0, -5, -5, 6, 6], [0, -1, 1, -2, 2]])

Z = get_clusters(X)
leaf_data, node_data, tree_data, cut_data = get_dendrogram_data(
    Z, groups=[0, 5, 6])
wrs = get_weak_relevance_scores(scores, Z, 5)
trace_data = get_trace_data(node_data, cut_data, wrs, tol=0.1)

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