2  scatter

import cellestial as cl
import scanpy as sc
from lets_plot import *

LetsPlot.setup_html()

data = sc.read("data/pbmc3k_mini.h5ad")

2.1 A simple scatter plot

A scatter plot is a type of plot that displays the relationship between two quantitative variables. The scatter plot is useful for visualizing the relationship between two continuous variables.

plot = (
    cl.scatter(
        data,
        x="pct_counts_mt",
        y="total_counts_ribo",
        aes_color="n_genes_by_counts",
        size=3,
    )
    + scale_y_log10()
    + ggsize(600, 400)
)

plot

2.2 Customizations

Add any layer you desire, from color palettes to size of the plot to theme components.

For example, you can simply modify or ‘ovewrite’ the color palette.

plot + scale_color_continuous(low="blue", high="red")

or make the plot interactive. note that it is also possible to make it zoomable and panable by setting the interactive argument to True when calling the function.

plot + ggtb()
# you can use the buttons from the toolbar to zoom in and out or move around the plot

and of course you can modify the theme componenents of the plot.

plot = (
    plot
    + labs(x="PCM", y="TCR", title="TCR vs PCM")  # modify labels
    + theme(
        axis_title=element_text(size=18, color="#6f6f6f"),  # modify axis titles
        title=element_text(
            family="monospace", size=20, color="#3f3f3f", face="bold"
        ),  # modify title elements
        axis_line=element_blank(),  # remove axis lines
        axis_ticks=element_blank(),  # remove axis ticks
        axis_text=element_text(size=16, face="italic"),  # remove axis text
        legend_position="bottom",  # move legend to bottom
    )
    + ggsize(700, 600)
    + ggtb()
)
plot
cl.versions()
cellestial: 0.2.0
scanpy: 1.10.4
anndata: 0.11.0
polars: 1.12.0