Plotting in giotto-tda

giotto-tda includes a set of plotting functions and class methods, powered by plotly. The library’s plotting API is designed to facilitate the exploration of intermediate results in pipelines by harnessing the highly visual nature of topological signatures.

This notebook is a quick tutorial on how to use giotto-tda’s plotting functionalities and unified plotting API. The plotting functions in gtda.mapper are not covered here as they are somewhat tailored to the Mapper algorithm, see the dedicated tutorial.

If you are looking at a static version of this notebook and would like to run its contents, head over to github.

License: AGPLv3

1. Basic philosophy and plot methods

The computational building blocks of giotto-tda are scikit-learn–style estimators. Typically, they are also transformers, i.e. they possess a transform and/or a fit-transform method which:

  • act on an array-like object X which collects a certain number of “samples” of a given kind;

  • return a transformed array-like object Xt which collects a (potentially different) number of “samples” of a potentially different kind.

The basic philosophy of giotto-tda’s class-level plotting API is to equip relevant transformers with plot methods taking two main arguments:

  • an object such as Xt above (i.e. consistent with the outputs of transform or fit-transform);

  • an integer index passed via the sample keyword and indicating which sample in Xt should be plotted.

In other words, <transformer>.plot(Xt, sample=i) will produce a plot of Xt[i] which is tailored to the nature of the samples in Xt.

1.1 Plotting functions

Several plot methods in giotto-tda actually fall back to specialised functions which can be found in the plotting subpackage and which can be used directly instead. However, unless the additional degree of control is necessary, plot methods should be preferred as they often exploit class parameters and/or attributes (e.g. those computed during fit) to automatically fill some parameters in the corresponding functions.

1.2 Example: Plotting persistence diagrams with VietorisRipsPersistence

Let’s take the example of VietorisRipsPersistence – a transformer also covered in another notebook. Let’s create the input collection X for this transformer as a collection of randomly generated point clouds, each containing 100 points positioned along two circles.

import numpy as np
np.random.seed(seed=42)
from gtda.homology import VietorisRipsPersistence
from sklearn.datasets import make_circles

X = np.asarray([
    make_circles(100, factor=np.random.random())[0]
    for i in range(10)
])

Incidentally, samples in X can be plotted using gtda.plotting.plot_point_cloud.

from gtda.plotting import plot_point_cloud
i = 0
plot_point_cloud(X[i])