3D Scatter

Single-Cell RNA-Seq UMAP Embedding

Single-cell transcriptomics UMAP visualization showing immune cell type clusters.

Output
Single-Cell RNA-Seq UMAP Embedding
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(999)

# Single-cell UMAP embedding
n_cells = 400

# Cell type clusters
cell_types = ['T cells', 'B cells', 'Monocytes', 'NK cells', 'Dendritic']
colors_types = ['#27D3F5', '#F5276C', '#6CF527', '#F5B027', '#4927F5']

all_x, all_y, all_z, all_c = [], [], [], []

for i, (ct, color) in enumerate(zip(cell_types, colors_types)):
    n = n_cells // 5
    angle = i * 2 * np.pi / 5 + np.random.uniform(-0.3, 0.3)
    r = np.random.uniform(2, 4)
    
    cx, cy = r * np.cos(angle), r * np.sin(angle)
    cz = np.random.uniform(-1, 1)
    
    x = np.random.normal(cx, 0.6, n)
    y = np.random.normal(cy, 0.6, n)
    z = np.random.normal(cz, 0.4, n)
    
    all_x.extend(x)
    all_y.extend(y)
    all_z.extend(z)
    all_c.extend([color] * n)

fig = plt.figure(figsize=(10, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d', facecolor='#ffffff')

ax.scatter(all_x, all_y, all_z, c=all_c, s=25, alpha=0.7, edgecolors='none')

ax.set_xlabel('UMAP 1', color='#1f2937', fontsize=10)
ax.set_ylabel('UMAP 2', color='#1f2937', fontsize=10)
ax.set_zlabel('UMAP 3', color='#1f2937', fontsize=10)
ax.set_title('Single-Cell RNA-Seq UMAP Embedding', color='#1f2937', fontsize=14, fontweight='bold', pad=20)

ax.tick_params(colors='#6b7280', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#e5e7eb')
ax.yaxis.pane.set_edgecolor('#e5e7eb')
ax.zaxis.pane.set_edgecolor('#e5e7eb')

ax.view_init(elev=20, azim=45)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support