Skip to content

Colour palettes

Built-in color palettes in PIASO

PIASO provides a diverse selection of discrete color palettes and continuous color palettes.

To use the built-in colors in PIASO, you can set palette=piaso.pl.color.d_color1 for discrete colors, and cmap=piaso.pl.color.c_color1 for continuous colors in piaso.pl.embedding, piaso.pl.plot_embeddings_split or other plotting functions. This notebook displays the available choices in both discrete and continuous color maps.

import piaso
import numpy as np
import matplotlib.pyplot as plt
import warnings
import piaso.plotting.color as color
piaso.settings.set_figure_params(style="cell")
warnings.simplefilter(action='ignore', category=FutureWarning)

Load the data

The 20k subsampled snRNA-seq data from Allen SEA-AD project is available in google drive: https://drive.google.com/file/d/1nH-CRaTQFxJ5pAVpy8_hUQn1nrIcakq2/view?usp=drive_link.

The original data is available in https://portal.brain-map.org/explore/seattle-alzheimers-disease.

adata = piaso.data.load_dataset("sea_ad_mtg_20k")
adata

Discrete color palettes

palettes = [c for c in vars(color) if c.startswith('d_')]
n = len(palettes)
ncol = 4
nrow = None
row_size, col_size = 2.4, 2.4
if ncol is None:
nrow = int(np.sqrt(n))
ncol = int(np.ceil(n / nrow))
else:
nrow = int(np.ceil(n / ncol))
fig, axs = plt.subplots(nrow, ncol, dpi=96, figsize=(ncol * col_size, nrow * row_size))
c = 0
for i in range(len(axs)):
for j in range(len(axs[0])):
if c < n:
palette_value = getattr(color, palettes[c], None)
piaso.pl.embedding(adata,
basis='X_umap',
color=['Subclass'],
palette=palette_value,
point_size=3,
frameon=False,
ax=axs[i][j],
title='piaso.plotting.color.'+str(palettes[c]+f' - {len(getattr(color, palettes[c], None))} colors'),
legend_loc='none',
show=False)
axs[i][j].title.set_size(9)
else:
axs[i][j].set_visible(False)
c += 1
plt.suptitle("Selection of discrete color palettes")
plt.tight_layout()
plt.show()
output

Continuous color palettes

palettes = [c for c in vars(color) if c.startswith('c_')]
n = len(palettes)
ncol = None
nrow = None
row_size, col_size = 2.3, 2.3
if ncol is None:
nrow = int(np.sqrt(n))
ncol = int(np.ceil(n / nrow))
else:
nrow = int(np.ceil(n / ncol))
fig, axs = plt.subplots(nrow, ncol, dpi=96, figsize=(ncol * col_size, nrow * row_size))
c = 0
for i in range(len(axs)):
for j in range(len(axs[0])):
if c < n:
palette_value = getattr(color, palettes[c], None)
piaso.pl.embedding(adata,
basis='X_umap',
color=['GAD1'],
cmap=palette_value,
point_size=3,
frameon=False,
ax=axs[i][j],
title='piaso.plotting.color.'+str(palettes[c]),
legend_loc='none',
show=False)
axs[i][j].title.set_size(9)
else:
axs[i][j].set_visible(False)
c += 1
plt.suptitle("Selection of continuous color palettes")
plt.tight_layout()
plt.show()
output