Saving Interactions as SVG
Let's first save the results from our homepage's quickstart into a plot object.
In [23]:
Copied!
from distortions.geometry import Geometry, bind_metric, local_distortions, neighborhoods
from distortions.visualization import dplot
import anndata as ad
import numpy as np
import scanpy as sc
adata = ad.AnnData(np.random.poisson(2, size=(100, 5)))
sc.pp.neighbors(adata, n_neighbors=15)
sc.tl.umap(adata)
geom = Geometry(affinity_kwds={"radius": 2}, adjacency_kwds={"n_neighbors": 15})
_, Hvv, Hs = local_distortions(adata.obsm["X_umap"], adata.X, geom)
embedding = bind_metric(adata.obsm["X_umap"], Hvv, Hs)
N = neighborhoods(adata, outlier_factor=1)
plot = dplot(embedding)\
.mapping(x="embedding_0", y="embedding_1")\
.inter_edge_link(N=N)\
.geom_ellipse()
from distortions.geometry import Geometry, bind_metric, local_distortions, neighborhoods
from distortions.visualization import dplot
import anndata as ad
import numpy as np
import scanpy as sc
adata = ad.AnnData(np.random.poisson(2, size=(100, 5)))
sc.pp.neighbors(adata, n_neighbors=15)
sc.tl.umap(adata)
geom = Geometry(affinity_kwds={"radius": 2}, adjacency_kwds={"n_neighbors": 15})
_, Hvv, Hs = local_distortions(adata.obsm["X_umap"], adata.X, geom)
embedding = bind_metric(adata.obsm["X_umap"], Hvv, Hs)
N = neighborhoods(adata, outlier_factor=1)
plot = dplot(embedding)\
.mapping(x="embedding_0", y="embedding_1")\
.inter_edge_link(N=N)\
.geom_ellipse()
If you print plot, you will see the figure. Hovering the mouse near a point highlights its neighbors. If you double click the figure, it freezes the interactivity.
In [24]:
Copied!
plot
plot
Out[24]:
dplot(dataset=[{'embedding_0': 6.433252811431885, 'embedding_1': 9.039752960205078, 'x0': -0.7191587756911096,…
To save a specific view, call the save()
method on the plot object. By default, it will save a file plot.svg
to the current notebook directory. You can specify your own path, but it must be an SVG file.
In [26]:
Copied!
plot.save()
plot.save()
One known limitation is that you have to at least hover over the SVG before the plot will properly save. This is because anywidget loads some utilities lazily, and we can't save until some interactions have been made.