{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# From linkage matrix to dendrogram\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The :func:`~pdendro.attach_dendrogram` function generates components of a dendrogram from\na linkage matrix and attaches them to a figure. Let us assume that we have the following data\npoints:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "X = [[0.0], [1.0], [3.0], [6.0]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The linkage matrix can be computed using the :func:`scipy.cluster.hierarchy.linkage` function:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import scipy\n\nZ = scipy.cluster.hierarchy.linkage(X)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then, a dendrogram can be drawn as follows:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import plotly.graph_objects as go\nimport plotly.io as pio\n\nfrom pdendro import attach_dendrogram\n\nfig = go.Figure()\nattach_dendrogram(fig, Z)\npio.show(fig)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.4" } }, "nbformat": 4, "nbformat_minor": 0 }