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
fig (bokeh.plotting.figure.Figure) – Figure on which a dendrogram is drawn.
leaf_data (pandas.DataFrame) – Data of leaves returned by
subrela.plot.get_dendrogram_datafunction.tree_data (pandas.DataFrame) – Data of tree lines returned by
subrela.plot.get_dendrogram_datafunction.cut_data (pandas.DataFrame) – Data of cut lines returned by
subrela.plot.get_dendrogram_datafunction.palette (list[str] or None, optional) – Color palette for groups. If
None,bokeh.palettes.Category10[10]is used.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.tree_kws (dict or None, optional) – Keyword argumsnts passed to
bokeh.plotting.Figure.multi_linemethod for drawing tree lines.cut_kws (dict or None, optional) – Keyword arguments passed to
bokeh.plotting.Figure.multi_linemethod for drawing cut lines.
- 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_kwscontains key'xs','ys', and'source'. Ifcut_kwscontains 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 frompalette[1:].If neither key
'line_color'nor key'color'is incut_kws,'black'is set to'line_color'. The default value forcut_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)