Launch binder

Compute interaction matrix

This example shows how to compute the interaction matrix.

The interaction matrix quantifies the number of edges that nodes belonging to a given annotation shares with the other annotations. It’s a descriptive statistics of the spatial graph.

import squidpy as sq

adata = sq.datasets.imc()


AnnData object with n_obs × n_vars = 4668 × 34
    obs: 'cell type'
    uns: 'cell type_colors'
    obsm: 'spatial'

First, we need to compute a connectivity matrix from spatial coordinates. We can use for this purpose.

We can compute the interaction matrix with Specify normalized = True if you want a row-normalized matrix. Results can be visualized with, cluster_key="cell type"), cluster_key="cell type")
Interaction matrix

Total running time of the script: ( 0 minutes 13.326 seconds)

Estimated memory usage: 11 MB