or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

analysis-tools.mddata-io.mddatasets.mdexternal-tools.mdindex.mdpreprocessing.mdqueries.mdspatial-analysis.mdutilities.mdvisualization.md

visualization.mddocs/

0

# Visualization

1

2

Scanpy's plotting module provides extensive visualization capabilities for single-cell data including scatter plots, heatmaps, violin plots, trajectory plots, and specialized single-cell visualizations. All plots are built on matplotlib and integrate seamlessly with the analysis workflow.

3

4

## Capabilities

5

6

### Embedding and Dimensionality Reduction Plots

7

8

Visualize low-dimensional representations of single-cell data.

9

10

```python { .api }

11

def umap(adata, color=None, use_raw=None, edges=False, arrows=False, sort_order=True, groups=None, components=None, projection='2d', legend_loc='right margin', legend_fontsize=None, legend_fontweight='bold', palette=None, color_map=None, frameon=None, right_margin=None, left_margin=None, size=None, title=None, save=None, ax=None, return_fig=None, **kwargs):

12

"""

13

Scatter plot in UMAP basis.

14

15

Parameters:

16

- adata (AnnData): Annotated data object

17

- color (str or list, optional): Keys for annotations of observations/cells or variables/genes

18

- use_raw (bool, optional): Use raw attribute of adata

19

- edges (bool): Show edges in neighborhood graph

20

- arrows (bool): Show arrows for RNA velocity

21

- sort_order (bool): Sort points by color values

22

- groups (str or list, optional): Restrict to these groups

23

- components (str or list, optional): Components to plot

24

- projection (str): Type of projection ('2d' or '3d')

25

- legend_loc (str): Location of legend

26

- legend_fontsize (int, optional): Legend font size

27

- legend_fontweight (str): Legend font weight

28

- palette (str, optional): Color palette

29

- color_map (str, optional): Colormap

30

- frameon (bool, optional): Draw frame around plot

31

- right_margin (float, optional): Right margin

32

- left_margin (float, optional): Left margin

33

- size (float, optional): Point size

34

- title (str, optional): Plot title

35

- save (str, optional): Save figure to file

36

- ax (Axes, optional): Matplotlib axes object

37

- return_fig (bool, optional): Return figure object

38

- **kwargs: Additional parameters

39

40

Returns:

41

None or Figure: Plot or figure object (if return_fig=True)

42

"""

43

44

def tsne(adata, color=None, use_raw=None, sort_order=True, groups=None, components=None, projection='2d', legend_loc='right margin', legend_fontsize=None, palette=None, color_map=None, frameon=None, right_margin=None, size=None, title=None, save=None, ax=None, return_fig=None, **kwargs):

45

"""

46

Scatter plot in t-SNE basis.

47

48

Parameters:

49

- adata (AnnData): Annotated data object

50

- color (str or list, optional): Keys for annotations

51

- use_raw (bool, optional): Use raw attribute

52

- sort_order (bool): Sort points by color values

53

- groups (str or list, optional): Restrict to groups

54

- components (str or list, optional): Components to plot

55

- projection (str): Type of projection

56

- legend_loc (str): Legend location

57

- legend_fontsize (int, optional): Legend font size

58

- palette (str, optional): Color palette

59

- color_map (str, optional): Colormap

60

- frameon (bool, optional): Draw frame

61

- right_margin (float, optional): Right margin

62

- size (float, optional): Point size

63

- title (str, optional): Plot title

64

- save (str, optional): Save figure

65

- ax (Axes, optional): Matplotlib axes

66

- return_fig (bool, optional): Return figure

67

- **kwargs: Additional parameters

68

69

Returns:

70

None or Figure: Plot or figure object

71

"""

72

73

def pca(adata, color=None, use_raw=None, sort_order=True, groups=None, components=None, projection='2d', legend_loc='right margin', legend_fontsize=None, palette=None, color_map=None, frameon=None, right_margin=None, size=None, title=None, save=None, ax=None, return_fig=None, **kwargs):

74

"""

75

Scatter plot in PCA coordinates.

76

77

Parameters:

78

- adata (AnnData): Annotated data object

79

- color (str or list, optional): Keys for annotations

80

- use_raw (bool, optional): Use raw attribute

81

- sort_order (bool): Sort points by color values

82

- groups (str or list, optional): Restrict to groups

83

- components (str or list, optional): Components to plot

84

- projection (str): Type of projection

85

- legend_loc (str): Legend location

86

- legend_fontsize (int, optional): Legend font size

87

- palette (str, optional): Color palette

88

- color_map (str, optional): Colormap

89

- frameon (bool, optional): Draw frame

90

- right_margin (float, optional): Right margin

91

- size (float, optional): Point size

92

- title (str, optional): Plot title

93

- save (str, optional): Save figure

94

- ax (Axes, optional): Matplotlib axes

95

- return_fig (bool, optional): Return figure

96

- **kwargs: Additional parameters

97

98

Returns:

99

None or Figure: Plot or figure object

100

"""

101

102

def diffmap(adata, color=None, components=None, **kwargs):

103

"""

104

Scatter plot in diffusion map basis.

105

106

Parameters:

107

- adata (AnnData): Annotated data object

108

- color (str or list, optional): Keys for annotations

109

- components (str or list, optional): Components to plot

110

- **kwargs: Additional plotting parameters

111

112

Returns:

113

None or Figure: Plot or figure object

114

"""

115

116

def draw_graph(adata, color=None, layout=None, **kwargs):

117

"""

118

Scatter plot in graph drawing coordinates.

119

120

Parameters:

121

- adata (AnnData): Annotated data object

122

- color (str or list, optional): Keys for annotations

123

- layout (str, optional): Graph layout to use

124

- **kwargs: Additional plotting parameters

125

126

Returns:

127

None or Figure: Plot or figure object

128

"""

129

130

def embedding(adata, basis, color=None, **kwargs):

131

"""

132

Scatter plot for any embedding in adata.obsm.

133

134

Parameters:

135

- adata (AnnData): Annotated data object

136

- basis (str): Basis key in obsm

137

- color (str or list, optional): Keys for annotations

138

- **kwargs: Additional plotting parameters

139

140

Returns:

141

None or Figure: Plot or figure object

142

"""

143

```

144

145

### Gene Expression Plots

146

147

Visualize gene expression patterns across cells.

148

149

```python { .api }

150

def scatter(adata, x=None, y=None, color=None, use_raw=None, layers=None, sort_order=True, alpha=None, basis=None, groups=None, components=None, projection='2d', legend_loc='right margin', legend_fontsize=None, legend_fontweight='bold', palette=None, color_map=None, frameon=None, right_margin=None, left_margin=None, size=None, title=None, save=None, ax=None, return_fig=None, **kwargs):

151

"""

152

Scatter plot along observations or variables axes.

153

154

Parameters:

155

- adata (AnnData): Annotated data object

156

- x (str, optional): x-coordinate

157

- y (str, optional): y-coordinate

158

- color (str or list, optional): Keys for annotations

159

- use_raw (bool, optional): Use raw attribute

160

- layers (str, optional): Layer to use for coloring

161

- sort_order (bool): Sort points by color values

162

- alpha (float, optional): Point transparency

163

- basis (str, optional): Embedding basis

164

- groups (str or list, optional): Restrict to groups

165

- components (str or list, optional): Components to plot

166

- projection (str): Type of projection

167

- legend_loc (str): Legend location

168

- legend_fontsize (int, optional): Legend font size

169

- legend_fontweight (str): Legend font weight

170

- palette (str, optional): Color palette

171

- color_map (str, optional): Colormap

172

- frameon (bool, optional): Draw frame

173

- right_margin (float, optional): Right margin

174

- left_margin (float, optional): Left margin

175

- size (float, optional): Point size

176

- title (str, optional): Plot title

177

- save (str, optional): Save figure

178

- ax (Axes, optional): Matplotlib axes

179

- return_fig (bool, optional): Return figure

180

- **kwargs: Additional parameters

181

182

Returns:

183

None or Figure: Plot or figure object

184

"""

185

186

def violin(adata, keys, groupby=None, log=False, use_raw=None, stripplot=True, jitter=0.4, size=1, layer=None, scale='width', order=None, multi_panel=None, xlabel='', ylabel='', rotation=None, ax=None, save=None, **kwds):

187

"""

188

Violin plot of gene expression.

189

190

Parameters:

191

- adata (AnnData): Annotated data object

192

- keys (str or list): Keys for accessing variables

193

- groupby (str, optional): Key for grouping observations

194

- log (bool): Plot on log scale

195

- use_raw (bool, optional): Use raw attribute

196

- stripplot (bool): Add strip plot

197

- jitter (float): Strip plot jitter

198

- size (float): Strip plot point size

199

- layer (str, optional): Layer to use

200

- scale (str): Violin scaling method

201

- order (list, optional): Order of groups

202

- multi_panel (bool, optional): Create multi-panel plot

203

- xlabel (str): x-axis label

204

- ylabel (str): y-axis label

205

- rotation (float, optional): Label rotation

206

- ax (Axes, optional): Matplotlib axes

207

- save (str, optional): Save figure

208

- **kwds: Additional parameters

209

210

Returns:

211

None or Axes: Plot or axes object

212

"""

213

214

def heatmap(adata, var_names, groupby=None, use_raw=None, log=False, num_categories=7, figsize=None, dendrogram=False, gene_symbols=None, var_group_positions=None, var_group_labels=None, var_group_rotation=None, layer=None, standard_scale=None, swap_axes=False, show_gene_labels=None, save=None, ax=None, vmin=None, vmax=None, vcenter=None, **kwds):

215

"""

216

Heatmap of gene expression across groups.

217

218

Parameters:

219

- adata (AnnData): Annotated data object

220

- var_names (list): Variable names

221

- groupby (str, optional): Key for grouping observations

222

- use_raw (bool, optional): Use raw attribute

223

- log (bool): Log transform values

224

- num_categories (int): Number of categories for continuous variables

225

- figsize (tuple, optional): Figure size

226

- dendrogram (bool): Show dendrogram

227

- gene_symbols (str, optional): Key for gene symbols

228

- var_group_positions (list, optional): Variable group positions

229

- var_group_labels (list, optional): Variable group labels

230

- var_group_rotation (float, optional): Variable group label rotation

231

- layer (str, optional): Layer to use

232

- standard_scale (str, optional): Standardization method

233

- swap_axes (bool): Swap axes

234

- show_gene_labels (bool, optional): Show gene labels

235

- save (str, optional): Save figure

236

- ax (Axes, optional): Matplotlib axes

237

- vmin (float, optional): Minimum value for colormap

238

- vmax (float, optional): Maximum value for colormap

239

- vcenter (float, optional): Center value for colormap

240

- **kwds: Additional parameters

241

242

Returns:

243

dict: Plot information

244

"""

245

```

246

247

### Specialized Plot Types

248

249

Advanced plotting functions for specific analysis types.

250

251

```python { .api }

252

def dotplot(adata, var_names, groupby, use_raw=None, log=False, num_categories=7, figsize=None, gene_symbols=None, var_group_positions=None, var_group_labels=None, var_group_rotation=None, layer=None, standard_scale=None, largest_dot=200.0, title=None, colorbar_title='Mean expression\\nin group', size_title='Fraction of cells\\nin group (%)', save=None, ax=None, return_fig=False, **kwds):

253

"""

254

Makes a dot plot of the expression values.

255

256

Parameters:

257

- adata (AnnData): Annotated data object

258

- var_names (list): Variable names to plot

259

- groupby (str): Key for grouping observations

260

- use_raw (bool, optional): Use raw attribute

261

- log (bool): Log transform values

262

- num_categories (int): Number of categories

263

- figsize (tuple, optional): Figure size

264

- gene_symbols (str, optional): Key for gene symbols

265

- var_group_positions (list, optional): Variable group positions

266

- var_group_labels (list, optional): Variable group labels

267

- var_group_rotation (float, optional): Variable group label rotation

268

- layer (str, optional): Layer to use

269

- standard_scale (str, optional): Standardization method

270

- largest_dot (float): Size of largest dot

271

- title (str, optional): Plot title

272

- colorbar_title (str): Colorbar title

273

- size_title (str): Size legend title

274

- save (str, optional): Save figure

275

- ax (Axes, optional): Matplotlib axes

276

- return_fig (bool): Return figure object

277

- **kwds: Additional parameters

278

279

Returns:

280

DotPlot or Figure: Plot object or figure

281

"""

282

283

def matrixplot(adata, var_names, groupby, use_raw=None, log=False, num_categories=7, figsize=None, gene_symbols=None, var_group_positions=None, var_group_labels=None, var_group_rotation=None, layer=None, standard_scale=None, colorbar_title='Mean expression\\nin group', title=None, save=None, ax=None, return_fig=False, **kwds):

284

"""

285

Creates a heatmap of the mean expression values per group.

286

287

Parameters:

288

- adata (AnnData): Annotated data object

289

- var_names (list): Variable names to plot

290

- groupby (str): Key for grouping observations

291

- use_raw (bool, optional): Use raw attribute

292

- log (bool): Log transform values

293

- num_categories (int): Number of categories

294

- figsize (tuple, optional): Figure size

295

- gene_symbols (str, optional): Key for gene symbols

296

- var_group_positions (list, optional): Variable group positions

297

- var_group_labels (list, optional): Variable group labels

298

- var_group_rotation (float, optional): Variable group label rotation

299

- layer (str, optional): Layer to use

300

- standard_scale (str, optional): Standardization method

301

- colorbar_title (str): Colorbar title

302

- title (str, optional): Plot title

303

- save (str, optional): Save figure

304

- ax (Axes, optional): Matplotlib axes

305

- return_fig (bool): Return figure object

306

- **kwds: Additional parameters

307

308

Returns:

309

MatrixPlot or Figure: Plot object or figure

310

"""

311

312

def stacked_violin(adata, var_names, groupby, use_raw=None, log=False, num_categories=7, figsize=None, gene_symbols=None, var_group_positions=None, var_group_labels=None, var_group_rotation=None, layer=None, standard_scale=None, title=None, save=None, ax=None, return_fig=False, **kwds):

313

"""

314

Stacked violin plots.

315

316

Parameters:

317

- adata (AnnData): Annotated data object

318

- var_names (list): Variable names to plot

319

- groupby (str): Key for grouping observations

320

- use_raw (bool, optional): Use raw attribute

321

- log (bool): Log transform values

322

- num_categories (int): Number of categories

323

- figsize (tuple, optional): Figure size

324

- gene_symbols (str, optional): Key for gene symbols

325

- var_group_positions (list, optional): Variable group positions

326

- var_group_labels (list, optional): Variable group labels

327

- var_group_rotation (float, optional): Variable group label rotation

328

- layer (str, optional): Layer to use

329

- standard_scale (str, optional): Standardization method

330

- title (str, optional): Plot title

331

- save (str, optional): Save figure

332

- ax (Axes, optional): Matplotlib axes

333

- return_fig (bool): Return figure object

334

- **kwds: Additional parameters

335

336

Returns:

337

StackedViolin or Figure: Plot object or figure

338

"""

339

340

def tracksplot(adata, var_names, groupby, use_raw=None, log=False, dendrogram=False, gene_symbols=None, var_group_positions=None, var_group_labels=None, var_group_rotation=None, layer=None, standard_scale=None, title=None, save=None, ax=None, return_fig=False, **kwds):

341

"""

342

Plot gene expression as tracks along groups.

343

344

Parameters:

345

- adata (AnnData): Annotated data object

346

- var_names (list): Variable names to plot

347

- groupby (str): Key for grouping observations

348

- use_raw (bool, optional): Use raw attribute

349

- log (bool): Log transform values

350

- dendrogram (bool): Show dendrogram

351

- gene_symbols (str, optional): Key for gene symbols

352

- var_group_positions (list, optional): Variable group positions

353

- var_group_labels (list, optional): Variable group labels

354

- var_group_rotation (float, optional): Variable group label rotation

355

- layer (str, optional): Layer to use

356

- standard_scale (str, optional): Standardization method

357

- title (str, optional): Plot title

358

- save (str, optional): Save figure

359

- ax (Axes, optional): Matplotlib axes

360

- return_fig (bool): Return figure object

361

- **kwds: Additional parameters

362

363

Returns:

364

None or Figure: Plot or figure object

365

"""

366

```

367

368

### Trajectory and Pseudotime Plots

369

370

Visualize developmental trajectories and pseudotime analysis.

371

372

```python { .api }

373

def paga(adata, basis='umap', color=None, alpha=None, groups=None, components=None, projection='2d', legend_loc='right margin', legend_fontsize=None, legend_fontweight='bold', palette=None, color_map=None, frameon=None, right_margin=None, left_margin=None, size=None, title=None, save=None, ax=None, return_fig=None, pos=None, labels=None, layout=None, init_pos=None, random_state=0, root=0, transitions=None, solid_edges='connectivities', dashed_edges=None, single_component=False, fontsize=None, fontcolor=None, textstyle='italic', fontweight='bold', fontfamily='sans-serif', edge_width_scale=5, arrowsize=30, node_size_scale=1.0, node_size_power=0.5, min_edge_width=None, max_edge_width=None, threshold=None, normalize_to_zero_one=False, cmap=None, use_raw=None, export_to_gexf=False, plot=True, **kwargs):

374

"""

375

Plot the abstracted graph through PAGA.

376

377

Parameters:

378

- adata (AnnData): Annotated data object

379

- basis (str): Embedding basis for nodes

380

- color (str or list, optional): Keys for node coloring

381

- alpha (float, optional): Transparency

382

- groups (str or list, optional): Restrict to groups

383

- components (str or list, optional): Components to plot

384

- projection (str): Type of projection

385

- legend_loc (str): Legend location

386

- legend_fontsize (int, optional): Legend font size

387

- legend_fontweight (str): Legend font weight

388

- palette (str, optional): Color palette

389

- color_map (str, optional): Colormap

390

- frameon (bool, optional): Draw frame

391

- right_margin (float, optional): Right margin

392

- left_margin (float, optional): Left margin

393

- size (float, optional): Point size

394

- title (str, optional): Plot title

395

- save (str, optional): Save figure

396

- ax (Axes, optional): Matplotlib axes

397

- return_fig (bool, optional): Return figure

398

- pos (array, optional): Node positions

399

- labels (list, optional): Node labels

400

- layout (str, optional): Graph layout

401

- init_pos (array, optional): Initial positions

402

- random_state (int): Random seed

403

- root (int): Root node

404

- transitions (str, optional): Transitions to show

405

- solid_edges (str): Solid edge type

406

- dashed_edges (str, optional): Dashed edge type

407

- single_component (bool): Show single component

408

- fontsize (int, optional): Font size

409

- fontcolor (str, optional): Font color

410

- textstyle (str): Text style

411

- fontweight (str): Font weight

412

- fontfamily (str): Font family

413

- edge_width_scale (float): Edge width scaling

414

- arrowsize (int): Arrow size

415

- node_size_scale (float): Node size scaling

416

- node_size_power (float): Node size power

417

- min_edge_width (float, optional): Minimum edge width

418

- max_edge_width (float, optional): Maximum edge width

419

- threshold (float, optional): Edge threshold

420

- normalize_to_zero_one (bool): Normalize edge weights

421

- cmap (str, optional): Colormap

422

- use_raw (bool, optional): Use raw attribute

423

- export_to_gexf (bool): Export to GEXF format

424

- plot (bool): Whether to plot

425

- **kwargs: Additional parameters

426

427

Returns:

428

None or Figure: Plot or figure object

429

"""

430

431

def dpt_groups_pseudotime(adata, color_map=None, palette=None, save=None, **kwargs):

432

"""

433

Plot groups and pseudotime.

434

435

Parameters:

436

- adata (AnnData): Annotated data object

437

- color_map (str, optional): Colormap

438

- palette (str, optional): Color palette

439

- save (str, optional): Save figure

440

- **kwargs: Additional parameters

441

442

Returns:

443

None: Creates plot

444

"""

445

446

def dpt_timeseries(adata, color_map=None, save=None, **kwargs):

447

"""

448

Heatmap of pseudotime series.

449

450

Parameters:

451

- adata (AnnData): Annotated data object

452

- color_map (str, optional): Colormap

453

- save (str, optional): Save figure

454

- **kwargs: Additional parameters

455

456

Returns:

457

None: Creates plot

458

"""

459

```

460

461

### Spatial Transcriptomics

462

463

Visualize spatial transcriptomics data.

464

465

```python { .api }

466

def spatial(adata, basis='spatial', color=None, use_raw=None, sort_order=True, alpha=None, groups=None, components=None, dimensions=None, layer=None, bw=None, contour=False, title=None, save=None, ax=None, return_fig=None, **kwargs):

467

"""

468

Plot spatial transcriptomics data.

469

470

Parameters:

471

- adata (AnnData): Annotated data object with spatial coordinates

472

- basis (str): Spatial coordinates key in obsm

473

- color (str or list, optional): Keys for coloring

474

- use_raw (bool, optional): Use raw attribute

475

- sort_order (bool): Sort points by color values

476

- alpha (float, optional): Transparency

477

- groups (str or list, optional): Restrict to groups

478

- components (str or list, optional): Components to plot

479

- dimensions (tuple, optional): Dimensions to plot

480

- layer (str, optional): Layer to use

481

- bw (str or float, optional): Bandwidth for density estimation

482

- contour (bool): Add contour lines

483

- title (str, optional): Plot title

484

- save (str, optional): Save figure

485

- ax (Axes, optional): Matplotlib axes

486

- return_fig (bool, optional): Return figure

487

- **kwargs: Additional parameters

488

489

Returns:

490

None or Figure: Plot or figure object

491

"""

492

```

493

494

### Ranking and Comparison Plots

495

496

Visualize gene rankings and group comparisons.

497

498

```python { .api }

499

def rank_genes_groups(adata, groups=None, n_genes=25, groupby=None, key='rank_genes_groups', fontsize=8, ncols=4, sharey=True, show=None, save=None, ax=None, **kwds):

500

"""

501

Plot ranking of genes using dotplot, heatmap or stacked_violin.

502

503

Parameters:

504

- adata (AnnData): Annotated data object

505

- groups (str or list, optional): Groups to plot

506

- n_genes (int): Number of genes to show

507

- groupby (str, optional): Key for grouping

508

- key (str): Key for ranked genes results

509

- fontsize (int): Font size

510

- ncols (int): Number of columns

511

- sharey (bool): Share y-axis

512

- show (bool, optional): Show plot

513

- save (str, optional): Save figure

514

- ax (Axes, optional): Matplotlib axes

515

- **kwds: Additional parameters

516

517

Returns:

518

None: Creates plot

519

"""

520

521

def rank_genes_groups_dotplot(adata, **kwargs):

522

"""Dotplot of ranked genes."""

523

524

def rank_genes_groups_heatmap(adata, **kwargs):

525

"""Heatmap of ranked genes."""

526

527

def rank_genes_groups_stacked_violin(adata, **kwargs):

528

"""Stacked violin plot of ranked genes."""

529

530

def rank_genes_groups_violin(adata, **kwargs):

531

"""Violin plot of ranked genes."""

532

533

def rank_genes_groups_tracksplot(adata, **kwargs):

534

"""Tracks plot of ranked genes."""

535

536

def rank_genes_groups_matrixplot(adata, **kwargs):

537

"""Matrix plot of ranked genes."""

538

```

539

540

### Quality Control Plots

541

542

Visualize data quality metrics and preprocessing results.

543

544

```python { .api }

545

def highest_expr_genes(adata, n_top=30, show=None, save=None, ax=None, **kwds):

546

"""

547

Plot the fraction of counts assigned to each gene over all cells.

548

549

Parameters:

550

- adata (AnnData): Annotated data object

551

- n_top (int): Number of top genes to show

552

- show (bool, optional): Show plot

553

- save (str, optional): Save figure

554

- ax (Axes, optional): Matplotlib axes

555

- **kwds: Additional parameters

556

557

Returns:

558

None: Creates plot

559

"""

560

561

def filter_genes_dispersion(adata, log=False, save=None, **kwds):

562

"""

563

Plot dispersions versus means for genes.

564

565

Parameters:

566

- adata (AnnData): Annotated data object

567

- log (bool): Log transform axes

568

- save (str, optional): Save figure

569

- **kwds: Additional parameters

570

571

Returns:

572

None: Creates plot

573

"""

574

575

def highly_variable_genes(adata, log=False, save=None, **kwds):

576

"""

577

Plot dispersions versus means for genes.

578

579

Parameters:

580

- adata (AnnData): Annotated data object

581

- log (bool): Log transform axes

582

- save (str, optional): Save figure

583

- **kwds: Additional parameters

584

585

Returns:

586

None: Creates plot

587

"""

588

589

def scrublet_score_distribution(adata, save=None, **kwds):

590

"""

591

Plot histogram of doublet scores.

592

593

Parameters:

594

- adata (AnnData): Annotated data object

595

- save (str, optional): Save figure

596

- **kwds: Additional parameters

597

598

Returns:

599

None: Creates plot

600

"""

601

```

602

603

### PCA-specific Plots

604

605

Specialized plots for principal component analysis results.

606

607

```python { .api }

608

def pca_loadings(adata, components=None, save=None, **kwds):

609

"""

610

Rank and plot PCA loadings.

611

612

Parameters:

613

- adata (AnnData): Annotated data object

614

- components (str or list, optional): Components to plot

615

- save (str, optional): Save figure

616

- **kwds: Additional parameters

617

618

Returns:

619

None: Creates plot

620

"""

621

622

def pca_overview(adata, save=None, **kwds):

623

"""

624

Plot PCA results overview.

625

626

Parameters:

627

- adata (AnnData): Annotated data object

628

- save (str, optional): Save figure

629

- **kwds: Additional parameters

630

631

Returns:

632

None: Creates plot

633

"""

634

635

def pca_variance_ratio(adata, log=False, n_pcs=50, save=None, **kwds):

636

"""

637

Variance ratio plot for PCA.

638

639

Parameters:

640

- adata (AnnData): Annotated data object

641

- log (bool): Log scale y-axis

642

- n_pcs (int): Number of PCs to show

643

- save (str, optional): Save figure

644

- **kwds: Additional parameters

645

646

Returns:

647

None: Creates plot

648

"""

649

```

650

651

### Plot Configuration

652

653

Functions for configuring plot appearance and behavior.

654

655

```python { .api }

656

def set_rcParams_scanpy(fontsize=14, color_map=None):

657

"""

658

Set matplotlib rcParams for scanpy.

659

660

Parameters:

661

- fontsize (float): Font size

662

- color_map (str, optional): Default colormap

663

664

Returns:

665

None: Modifies matplotlib rcParams

666

"""

667

668

def set_rcParams_defaults():

669

"""

670

Reset matplotlib rcParams to defaults.

671

672

Returns:

673

None: Resets matplotlib rcParams

674

"""

675

```

676

677

### Plot Classes

678

679

Object-oriented plotting interface for complex visualizations.

680

681

```python { .api }

682

class DotPlot:

683

"""Dotplot of gene expression."""

684

685

def __init__(self, adata, var_names, groupby, **kwargs):

686

"""Initialize DotPlot object."""

687

688

def add_totals(self, **kwargs):

689

"""Add total counts."""

690

691

def legend(self, **kwargs):

692

"""Add legend."""

693

694

def show(self, **kwargs):

695

"""Show plot."""

696

697

def save(self, filename, **kwargs):

698

"""Save plot."""

699

700

class MatrixPlot:

701

"""Matrix plot of gene expression."""

702

703

def __init__(self, adata, var_names, groupby, **kwargs):

704

"""Initialize MatrixPlot object."""

705

706

def add_totals(self, **kwargs):

707

"""Add total counts."""

708

709

def show(self, **kwargs):

710

"""Show plot."""

711

712

def save(self, filename, **kwargs):

713

"""Save plot."""

714

715

class StackedViolin:

716

"""Stacked violin plot."""

717

718

def __init__(self, adata, var_names, groupby, **kwargs):

719

"""Initialize StackedViolin object."""

720

721

def add_totals(self, **kwargs):

722

"""Add total counts."""

723

724

def show(self, **kwargs):

725

"""Show plot."""

726

727

def save(self, filename, **kwargs):

728

"""Save plot."""

729

```

730

731

## Usage Examples

732

733

### Basic Embedding Visualization

734

735

```python

736

import scanpy as sc

737

738

# UMAP with cluster coloring

739

sc.pl.umap(adata, color='leiden', legend_loc='on data',

740

title='Leiden clustering', frameon=False, save='.pdf')

741

742

# Multiple features

743

sc.pl.umap(adata, color=['leiden', 'CD3E', 'CD14'], ncols=3)

744

745

# Gene expression

746

sc.pl.umap(adata, color='CD3E', use_raw=False, color_map='viridis')

747

```

748

749

### Gene Expression Analysis

750

751

```python

752

# Violin plots

753

sc.pl.violin(adata, ['CD3E', 'CD14', 'CD79A'], groupby='leiden')

754

755

# Heatmap

756

sc.pl.heatmap(adata, var_names=['CD3E', 'CD14'], groupby='leiden',

757

show_gene_labels=True)

758

759

# Dotplot for marker genes

760

marker_genes = ['CD3E', 'CD4', 'CD8A', 'CD14', 'CD68', 'CD79A']

761

sc.pl.dotplot(adata, marker_genes, groupby='leiden')

762

```

763

764

### Trajectory Visualization

765

766

```python

767

# PAGA plot

768

sc.pl.paga(adata, plot=False) # compute positions

769

sc.pl.paga(adata, color=['leiden'], title='PAGA graph')

770

771

# Pseudotime

772

sc.pl.umap(adata, color=['leiden', 'dpt_pseudotime'],

773

legend_loc='on data')

774

```

775

776

### Quality Control Visualization

777

778

```python

779

# QC metrics

780

sc.pl.violin(adata, ['n_genes_by_counts', 'total_counts', 'pct_counts_mt'],

781

jitter=0.4, multi_panel=True)

782

783

# Highest expressing genes

784

sc.pl.highest_expr_genes(adata, n_top=20)

785

786

# Highly variable genes

787

sc.pl.highly_variable_genes(adata)

788

789

# PCA variance

790

sc.pl.pca_variance_ratio(adata, log=True, n_pcs=50)

791

```