Plotting
Mixin for convenient plots/visualization of pAnnData object. Typically a wrapper of functions from the scpviz.plotting module.
Convenient plotting wrappers for visualizing a pAnnData object.
Most methods forward to functions in the scpviz.plotting module, keeping
axes-level control while binding abundance, metadata, and RS context from
the parent object.
Methods:
| Name | Description |
|---|---|
plot_counts |
Violin plot of per-sample count metrics from |
plot_rs |
Histograms of protein–peptide connectivity in the RS matrix. |
plot_abundance |
Abundance strip/box/violin plot for selected features. |
plot_abundance_boxgrid |
Faceted abundance box/violin/line/bar grid. |
plot_pairwise_correlation |
Pairwise sample correlation heatmap. |
plot_pca_protein_vectors |
PCA biplot with protein loading vectors. |
plot_pca_gsea_pathway_vectors |
PCA biplot with GSEA pathway vectors. |
plot_pca_gsea_bubble |
Bubble plot of PCA–GSEA enrichment results. |
plot_pca_gsea_heatmap |
Heatmap of PCA–GSEA enrichment results. |
plot_grouped_heatmap |
Grouped abundance heatmap. |
plot_clustered_heatmap |
Clustered abundance heatmap. |
plot_clustermap |
Overview heatmap with row + column dendrograms. |
Source code in src/scpviz/pAnnData/plot.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 | |
plot_abundance
plot_abundance(
ax=None,
namelist=None,
layer="X",
on="protein",
classes=None,
return_df=False,
order=None,
palette=None,
log=True,
facet=None,
height=4,
aspect=0.5,
plot_points=True,
x_label="gene",
kind="auto",
**kwargs: Any
)
Plot abundance of proteins or peptides across samples.
Thin wrapper around :func:scpviz.plotting.plot_abundance.
This function visualizes expression values for selected proteins or peptides using violin + box + strip plots, or bar plots when the number of replicates per group is small. Supports grouping, faceting, and custom ordering.
Important default behavior:
- This method defaults to log=True (log2-transformed abundances on a linear y-axis).
- With log=False, abundances remain raw and the y-axis is log10-scaled, so the
plot displays log10(abundance) without transforming the underlying values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axis to plot on. Ignored if |
None
|
namelist
|
list of str
|
List of accessions or gene names to plot. If None, all available features are considered. |
None
|
layer
|
str
|
Data layer to use for abundance values. Default is |
'X'
|
on
|
str
|
Data level to plot, either |
'protein'
|
classes
|
str or list of str
|
|
None
|
return_df
|
bool
|
If True, returns the DataFrame of replicate and summary values. |
False
|
order
|
dict or list
|
Custom order of classes. For dictionary input,
keys are class names and values are the ordered categories.
Example: |
None
|
palette
|
list or dict
|
Color palette mapping groups to colors. |
None
|
log
|
bool
|
If True, apply log2 transformation to abundance values (default here). If False, raw values are used and the y-axis is log10-scaled. |
True
|
facet
|
str
|
|
None
|
height
|
float
|
Height of each facet plot. Default is 4. |
4
|
aspect
|
float
|
Aspect ratio of each facet plot. Default is 0.5. |
0.5
|
plot_points
|
bool
|
Whether to overlay stripplot of individual samples. |
True
|
x_label
|
str
|
Label for the x-axis, either |
'gene'
|
kind
|
str
|
Type of plot. Options:
|
'auto'
|
**kwargs
|
Any
|
Additional keyword arguments passed to seaborn plotting functions. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes or FacetGrid
|
The axis or facet grid containing the plot. |
df |
(DataFrame, optional)
|
Returned if |
Example
Plot abundance of selected marker proteins grouped by cell line and condition:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(4, 4))
pdata.plot_abundance(
ax, namelist=["GAPDH", "TUBB", "ACTB"], classes=["cellline", "condition"]
)
plt.show()

Source code in src/scpviz/pAnnData/plot.py
plot_abundance_boxgrid
plot_abundance_boxgrid(
namelist=None,
ax=None,
layer="X",
on="protein",
classes="Grouping",
return_df=False,
order=None,
plot_type="box",
log_scale=False,
figsize=(2, 2),
palette=None,
y_min=None,
y_max=None,
label_x=True,
show_n=False,
global_legend=True,
box_kwargs=None,
hline_kwargs=None,
bar_kwargs=None,
bar_error="sd",
violin_kwargs=None,
text_kwargs=None,
strip_kwargs=None,
sig_pairs=None,
sig_kwargs=None,
nd_kwargs=None,
)
Plot abundance values in a one-row panel of boxplots, mean-lines, bars, or violins.
This function generates a clean horizontal panel, with one subplot per gene,
using plot_type to select boxplots (default), mean-lines, bar plots, or
violin plots. If log_scale=True, abundance values are visualized in
log10 units (with zero or negative values clipped to 0 before transformation).
The layout is optimized for compact manuscript figure panels and supports
custom global legends, count annotations, and flexible formatting via keyword
dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namelist
|
list of str
|
List of accessions or gene names to plot. If None, all available features are considered. |
None
|
ax
|
Axes
|
Axis to plot on. Generates a new axis if None. |
None
|
layer
|
str
|
Data layer to use for abundance values. Default is |
'X'
|
on
|
str
|
Data level to plot, either |
'protein'
|
classes
|
str or list of str
|
Column in |
'Grouping'
|
return_df
|
bool
|
If True, returns the DataFrame of replicate and summary values. |
False
|
order
|
list of str
|
Ordered list to plot by. If None, plots by given dataframe order. |
None
|
plot_type
|
str
|
Type of plot, select from one of |
'box'
|
log_scale
|
bool
|
If True, plot log10-transformed abundances on a linear axis. If False (default), plot raw abundance values on a linear axis. |
False
|
figsize
|
tuple
|
Figure size as (width, height) in inches. |
(2, 2)
|
palette
|
dict or list
|
Color palette for grouping categories.
Defaults to |
None
|
y_min
|
float or None
|
Lower y-axis limit in plotting units. If |
None
|
y_max
|
float or None
|
Upper y-axis limit in plotting units. If |
None
|
label_x
|
bool
|
Whether to display x tick labels inside each subplot. |
True
|
show_n
|
bool
|
Whether to annotate each subplot with sample counts. |
False
|
global_legend
|
bool
|
Whether to display a single global legend. |
True
|
box_kwargs
|
dict
|
Additional arguments passed to |
None
|
hline_kwargs
|
dict
|
Styling for mean segments when |
None
|
bar_kwargs
|
dict
|
Passed to |
None
|
bar_error
|
str
|
Error bar for bar plot. Select from one of
|
'sd'
|
violin_kwargs
|
dict
|
Additional arguments passed to |
None
|
text_kwargs
|
dict
|
Keyword arguments for count labels (e.g., fontsize, offset). |
None
|
strip_kwargs
|
dict
|
Keyword arguments for strip (raw points),
e.g. |
None
|
sig_pairs
|
list, bool, or None
|
Pairwise comparisons for significance brackets.
|
None
|
sig_kwargs
|
dict
|
Significance options merged onto defaults
|
None
|
nd_kwargs
|
dict
|
Not-detected annotation options merged onto defaults
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
The generated figure. |
axes |
list of matplotlib.axes.Axes
|
One axis per gene. |
df |
(DataFrame, optional)
|
Returned if |
stats_df |
(DataFrame, optional)
|
Returned if |
Note
Default customizations for keyword dictionaries:
Boxplot styling (used when plot_type="box"):
box_kwargs = {
"showcaps": False,
"whiskerprops": {"visible": False},
"showfliers": False,
"boxprops": {"alpha": 0.6, "linewidth": 1},
"linewidth": 1,
"dodge": True,
}
Mean-line styling (used when plot_type="line"):
half_width is in x-axis units; lower it when several classes are dodged
and mean segments would cross.
Bar styling (used when plot_type="bar"):
bar_kwargs = {
"alpha": 0.8,
"edgecolor": "black",
"linewidth": 0.6,
"width": 0.3,
"capsize": 2,
"zorder": 3,
}
width is passed to Axes.bar (x-axis units); use a smaller value when
bars from neighboring hue levels overlap.
Violin styling (used when plot_type="violin"):
Strip styling (raw points; used for all plot types):
Text annotation styling (used when show_n=True):
Example
Basic usage (grouped boxplots):
fig, axes = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
plot_type="box",
figsize=(2, 2.5),
)
plt.show()

Bar plots with error bars:
fig, axes = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
plot_type="bar",
bar_error="sd", # "sd", "sem", None, or callable
bar_kwargs={"width": 0.14}, # narrower bars when many groups dodge
figsize=(2, 2.5),
)
plt.show()

Mean-lines with count annotations:
fig, axes = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
plot_type="line",
show_n=True,
hline_kwargs={"half_width": 0.08}, # shorter segments when groups dodge
figsize=(2, 2.5),
)
plt.show()

Violin plots (distribution-focused):
fig, axes = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
plot_type="violin",
figsize=(2, 2.5),
)
plt.show()

Customizing appearance (palette, order, and styling):
fig, axes = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
plot_type="box",
box_kwargs={"boxprops": {"alpha": 0.45}, "linewidth": 1.2},
strip_kwargs={"size": 4, "alpha": 0.6},
figsize=(2, 2.5),
)
plt.show()

Return the plotting DataFrame for downstream checks:
fig, axes, df = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
plot_type="box",
return_df=True,
)
display(df.head())
plt.show()

Significance brackets (explicit pairs, volcano-style dicts):
fig, axes, df, stats = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
sig_pairs=[
({"cellline": "BE", "condition": "sc"}, {"cellline": "BE", "condition": "kd"}),
({"cellline": "AS", "condition": "sc"}, {"cellline": "AS", "condition": "kd"}),
],
sig_kwargs={"fontsize": 8},
return_df=True,
)
plt.show()

Multiple comparisons with a shared group (same group may appear in more than one pair):
fig, axes = pdata.plot_abundance_boxgrid(
namelist=["GAPDH", "TUBB", "ACTB"],
classes=["cellline", "condition"],
sig_pairs=[
({"cellline": "BE", "condition": "sc"}, {"cellline": "BE", "condition": "kd"}),
({"cellline": "BE", "condition": "kd"}, {"cellline": "AS", "condition": "kd"}),
],
sig_kwargs={"fontsize": 8},
)
plt.show()

Two hue groups only — auto comparison:
Source code in src/scpviz/pAnnData/plot.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
plot_clustered_heatmap
plot_clustered_heatmap(
classes,
proteins=None,
stats_key=None,
significance_categories=None,
protein_groups=None,
on="protein",
sort_by=None,
layer="X",
display_scale="auto",
metric="correlation",
cor_method="pearson",
linkage_method="average",
optimal_ordering=True,
show_unassigned=True,
group_colors=None,
header_colors=None,
label_color=None,
sample_label_col=None,
cmap=None,
figsize=None,
text_size=8,
cbar_scale=1.0,
legend_width=None,
column_spacing=True,
header_spacing=0.06,
header_height=0.35,
dendrogram_linewidth=None,
auto_log2=True,
gene_col="Genes",
separate_legend=False,
**kwargs
)
Plot a hierarchically clustered protein/peptide × sample heatmap.
Thin wrapper around :func:scpviz.plotting.plot_clustered_heatmap.
Provide exactly one of proteins or stats_key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
list of str
|
|
required |
proteins
|
list of str
|
Explicit feature list. |
None
|
stats_key
|
str
|
|
None
|
significance_categories
|
list of str or str
|
Categories kept
for |
None
|
protein_groups
|
dict
|
Annotation overlay for the color strip. |
None
|
on
|
str
|
|
'protein'
|
sort_by
|
dict
|
Per-class category order. |
None
|
layer
|
str
|
Abundance layer (default |
'X'
|
display_scale
|
str
|
|
'auto'
|
metric
|
str
|
|
'correlation'
|
cor_method
|
str
|
|
'pearson'
|
linkage_method
|
str
|
Passed to scipy linkage (default |
'average'
|
optimal_ordering
|
bool
|
Improve leaf order for display (default True). |
True
|
show_unassigned
|
bool
|
If False, drop features not in |
True
|
group_colors
|
dict
|
Override colors for the group strip/legend. |
None
|
header_colors
|
dict
|
Header strip colors. Nested
|
None
|
label_color
|
str
|
Fixed color for all gene row labels
(e.g. |
None
|
sample_label_col
|
str
|
|
None
|
cmap
|
str
|
Colormap; |
None
|
figsize
|
tuple
|
Figure size; auto if None. |
None
|
text_size
|
int
|
Base font size for ticks, colorbar, and legends
(default 8; same convention as |
8
|
cbar_scale
|
float
|
Vertical scale factor for the colorbar (default
|
1.0
|
legend_width
|
float
|
Left margin for colorbar + legends.
|
None
|
column_spacing
|
bool or float
|
Horizontal gaps between sample leaf
blocks. |
True
|
header_spacing
|
float
|
Space between header strips and the heatmap
(default |
0.06
|
header_height
|
float
|
Relative GridSpec height for each header strip
(default |
0.35
|
dendrogram_linewidth
|
float
|
Line width for the cluster
tree. |
None
|
auto_log2
|
bool
|
In-memory log2 when layer looks linear. |
True
|
gene_col
|
str
|
|
'Genes'
|
separate_legend
|
bool
|
If True, return |
False
|
**kwargs
|
Forwarded (e.g. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
Constructed figure, or |
|
|
Example
Cluster an explicit protein list:
fig = pdata.plot_clustered_heatmap(
classes=["treatment", "cellline"],
proteins=["CDK1", "PCNA", "HSPA1A", "GAPDH"],
protein_groups={"Cell cycle": ["CDK1", "PCNA"]},
)
Cluster DE hits from a stored contrast (default up + down):
fig = pdata.plot_clustered_heatmap(
classes=["condition"],
stats_key="SWI vs Uninjured",
sort_by={"condition": ["SWI", "Uninjured"]},
)
Fonts, display scale, colorbar height, and a separate legend:
fig, legend_fig = pdata.plot_clustered_heatmap(
classes=["condition"],
stats_key="SWI vs Uninjured",
significance_categories=["not comparable"],
sample_label_col="replicate",
label_color="black",
display_scale="log",
text_size=10,
cbar_scale=0.8,
legend_width=0.36,
dendrogram_linewidth=0.8,
separate_legend=True,
)
Source code in src/scpviz/pAnnData/plot.py
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 | |
plot_clustermap
plot_clustermap(
classes,
namelist=None,
on="protein",
layer="X",
display_scale="auto",
metric="correlation",
cor_method="pearson",
linkage_method="average",
optimal_ordering=True,
header_colors=None,
sample_label_col=None,
cmap=None,
figsize=None,
text_size=8,
cbar_scale=1.0,
legend_width=None,
header_spacing=0.06,
header_height=0.35,
dendrogram_linewidth=None,
show_row_labels=False,
auto_log2=True,
gene_col="Genes",
separate_legend=False,
**kwargs
)
Plot an overview clustered heatmap with row and column dendrograms.
Thin wrapper around :func:scpviz.plotting.plot_clustermap. Sample order
follows the column dendrogram (not metadata sort).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
list of str
|
|
required |
namelist
|
list of str
|
Gene/accession subset; |
None
|
on
|
str
|
|
'protein'
|
layer
|
str
|
Abundance layer (default |
'X'
|
display_scale
|
str
|
|
'auto'
|
metric
|
str
|
|
'correlation'
|
cor_method
|
str
|
|
'pearson'
|
linkage_method
|
str
|
Scipy linkage method (default |
'average'
|
optimal_ordering
|
bool
|
Improve leaf order for display. |
True
|
header_colors
|
dict
|
Header strip colors (same as grouped). |
None
|
sample_label_col
|
str
|
|
None
|
cmap
|
str
|
Colormap; |
None
|
figsize
|
tuple
|
Figure size; auto if None. |
None
|
text_size
|
int
|
Base font size (default 8). |
8
|
cbar_scale
|
float
|
Colorbar vertical scale (default |
1.0
|
legend_width
|
float
|
Left margin for colorbar + legends. |
None
|
header_spacing
|
float
|
Space between headers and heatmap. |
0.06
|
header_height
|
float
|
Relative header strip height. |
0.35
|
dendrogram_linewidth
|
float
|
Dendrogram line width. |
None
|
show_row_labels
|
bool
|
Show feature labels (default False). |
False
|
auto_log2
|
bool
|
In-memory log2 when layer looks linear. |
True
|
gene_col
|
str
|
|
'Genes'
|
separate_legend
|
bool
|
If True, return |
False
|
**kwargs
|
Optional |
{}
|
Returns:
| Type | Description |
|---|---|
|
fig or |
Source code in src/scpviz/pAnnData/plot.py
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 | |
plot_counts
Violin plot of per-sample count metrics from pdata.summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
Column in |
None
|
|
y
|
str
|
Column to plot (default |
'protein_count'
|
**kwargs
|
Forwarded to |
{}
|
Source code in src/scpviz/pAnnData/plot.py
plot_grouped_heatmap
plot_grouped_heatmap(
protein_groups,
classes,
on="protein",
sort_by=None,
layer="X",
display_scale="auto",
group_colors=None,
header_colors=None,
cmap=None,
row_spacing=True,
column_spacing=True,
header_spacing=0.06,
header_height=0.35,
group_bar_pad=0.25,
group_bar_width=0.4,
sample_label_col=None,
figsize=None,
text_size=8,
cbar_scale=1.0,
legend_width=None,
auto_log2=True,
gene_col="Genes",
separate_legend=False,
**kwargs
)
Plot a curated protein-group × sample heatmap with header strips.
Thin wrapper around :func:scpviz.plotting.plot_grouped_heatmap.
Filter samples on the object beforehand if you need a subset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protein_groups
|
dict
|
|
required |
classes
|
list of str
|
|
required |
on
|
str
|
|
'protein'
|
sort_by
|
dict
|
Per-class category order. |
None
|
layer
|
str
|
Abundance layer (default |
'X'
|
display_scale
|
str
|
|
'auto'
|
group_colors
|
dict
|
Override colors for group brackets/legend. |
None
|
header_colors
|
dict
|
Header strip colors. Nested
|
None
|
cmap
|
str
|
Colormap; |
None
|
row_spacing
|
bool or float
|
Vertical gaps between protein groups.
|
True
|
column_spacing
|
bool or float
|
Horizontal gaps between sample leaf
blocks. |
True
|
header_spacing
|
float
|
Space between header strips and the heatmap
(default |
0.06
|
header_height
|
float
|
Relative GridSpec height for each header strip
(default |
0.35
|
group_bar_pad
|
float
|
Horizontal gap between heatmap and group bars (default 0.25). |
0.25
|
group_bar_width
|
float
|
Width of colored group bars in sample-column
units (default |
0.4
|
sample_label_col
|
str
|
|
None
|
figsize
|
tuple
|
Figure size; auto if None. |
None
|
text_size
|
int
|
Base font size for ticks, colorbar, and legends
(default 8; same convention as |
8
|
cbar_scale
|
float
|
Vertical scale factor for the colorbar (default
|
1.0
|
legend_width
|
float
|
Left margin for colorbar + legends.
|
None
|
auto_log2
|
bool
|
In-memory log2 when layer looks linear. |
True
|
gene_col
|
str
|
|
'Genes'
|
separate_legend
|
bool
|
If True, return |
False
|
**kwargs
|
Forwarded (e.g. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
Constructed figure, or |
|
|
Example
Grouped pathway heatmap with condition headers:
fig = pdata.plot_grouped_heatmap(
{
"Cell cycle": ["CDK1", "CDK2", "PCNA"],
"Stress": ["HSPA1A", "HSP90AA1"],
},
classes=["treatment", "cellline"],
sort_by={"treatment": ["DMSO", "Drug"]},
)
Custom header and group colors (via get_color or hex).
Single class may use a flat map; multiple classes nest by class:
from scpviz import plotting as scplt
c = scplt.get_color("colors", 7)
fig = pdata.plot_grouped_heatmap(
{"Cell cycle": ["Cdk1", "Pcna"], "Stress": ["Hspa1a"]},
classes=["condition"],
sort_by={"condition": ["SWI", "Uninjured"]},
group_colors={"Cell cycle": c[0], "Stress": c[1]},
header_colors={"SWI": "#FF0000", "Uninjured": "#6EDC00"},
)
Spacing, fonts, display scale, and colorbar height:
fig = pdata.plot_grouped_heatmap(
{"Cell cycle": ["Cdk1", "Pcna"], "Stress": ["Hspa1a"]},
classes=["condition"],
sample_label_col="replicate",
row_spacing=True,
group_bar_pad=0.15,
column_spacing=0.5,
header_spacing=0.06,
display_scale="zscore",
text_size=10,
cbar_scale=0.8,
legend_width=0.36,
)
Separate legend figure when resizing the heatmap:
Source code in src/scpviz/pAnnData/plot.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 | |
plot_pairwise_correlation
plot_pairwise_correlation(
classes: str | list[str],
on: str = "protein",
layer: str = "X",
method: str = "pearson",
order: list | None = None,
show_samples: bool = False,
cmap: str = "RdBu_r",
vmin: float | None = None,
vmax: float | None = None,
annotation_cmap: str | dict | list = "default",
figsize: tuple | None = None,
text_size: int = 9,
colorbar_label: str | None = None,
annot: bool = False,
annot_fmt: str = ".2f",
annot_size: int = 7,
title: str | None = None,
force: bool = False,
subset_mask=None,
show_annotation_legend: bool = True,
legend_anchor_x: float = 0.3,
show_ticklabels: bool | None = None,
ticklabels_auto_max_samples: int = 20,
)
Plot a pairwise protein/peptide abundance correlation heatmap across groups or samples in .obs.
Thin wrapper around :func:scpviz.plotting.plot_pairwise_correlation.
Automatically runs :meth:~scpviz.pAnnData.pAnnData.pairwise_correlation if
results are not already cached (or if force=True). The figure is created
internally; no ax argument is needed.
Cached analysis results are reused when classes, method, layer, and
subset_mask (via the same key as pairwise_correlation) match. If
show_samples=True but the cache lacks a sample matrix, analysis is rerun with
compute_sample_matrix=True. Group-level plots may reuse a cache that already
includes a sample matrix (nothing is stripped). Display order is applied only
when drawing and does not require recomputation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
str | list[str]
|
|
required |
on
|
str
|
|
'protein'
|
layer
|
str
|
Data layer (default |
'X'
|
method
|
str
|
|
'pearson'
|
order
|
list | None
|
Optional row/column order. Must match the matrix being plotted:
If |
None
|
show_samples
|
bool
|
If False (default), plot the group × group matrix. If True,
plot the sample × sample matrix (requires |
False
|
cmap
|
str
|
Matplotlib colormap for the heatmap. |
'RdBu_r'
|
vmin
|
float | None
|
Colormap lower limit; correlation methods default to |
None
|
vmax
|
float | None
|
Colormap upper limit; correlation methods default to |
None
|
annotation_cmap
|
str | dict | list
|
|
'default'
|
figsize
|
tuple | None
|
|
None
|
text_size
|
int
|
Base font size for ticks, colorbar, and legends. |
9
|
colorbar_label
|
str | None
|
Override colorbar label. |
None
|
annot
|
bool
|
If True, write numeric values in each cell. |
False
|
annot_fmt
|
str
|
Format string for cell annotations (e.g. |
'.2f'
|
annot_size
|
int
|
Font size for cell annotations. |
7
|
title
|
str | None
|
Optional figure suptitle. |
None
|
force
|
bool
|
If True, recompute |
False
|
subset_mask
|
Boolean mask or boolean |
None
|
|
show_annotation_legend
|
bool
|
If True (default), draw one legend per annotation track in a dedicated GridSpec column right of the colorbar. |
True
|
legend_anchor_x
|
float
|
Horizontal anchor for annotation legends inside the legend
column, in axes coordinates ( |
0.3
|
show_ticklabels
|
bool | None
|
When |
None
|
ticklabels_auto_max_samples
|
int
|
When |
20
|
Returns:
| Type | Description |
|---|---|
|
|
Note
Heatmap row (y) tick labels are always omitted (symmetric matrix; x-axis labels
carry sample or group names as applicable).
The order argument lists group labels when show_samples=False
(including combined strings such as "AS, kd" for multi-column classes),
but lists observation names when show_samples=True.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
Group-level heatmap (show_samples=False, default):

Sample × sample heatmap with x-axis sample names forced on:
fig, ax = pdata.plot_pairwise_correlation(
classes="cellline",
show_samples=True,
show_ticklabels=True,
)
Custom row/column order without recomputing (group labels must match the matrix):
fig, ax = pdata.plot_pairwise_correlation(
classes=["cellline", "treatment"],
order=["AS, kd", "BE, sc", "AS, sc", "BE, kd"],
)
Subset of samples and no annotation legends:
Source code in src/scpviz/pAnnData/plot.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
plot_pca_gsea_bubble
plot_pca_gsea_bubble(
ax,
on="protein",
key_added="pca_gsea",
pcs=None,
top_n=20,
fdr_cutoff=0.1,
size_scale=0.85,
size_fdr_cap=5.0,
pc_pad=0.6,
cbar_scale=1.0,
cmap="coolwarm",
title_case_labels=True,
force=False,
gsea_kwargs=None,
top_n_mode="balanced",
include_pathways=None,
exclude_pathways=None,
return_df=False,
)
Plot PCA-GSEA results as a bubble chart (principal component versus pathway).
Thin wrapper around :func:scpviz.plotting.plot_pca_gsea_bubble.
Bubble color encodes NES; bubble area reflects significance (-log10(FDR)). Rows and columns
are ordered by pathway and PC. If pcs is omitted, all PCs present in stored results are used.
Bubble diameters are sized relative to the current figure/axes and the PC × pathway grid, so
choose figsize before calling this function. Marker areas are computed once at plot time
(they do not auto-update on interactive window resize). Column spacing uses pc_pad;
pathway rows keep unit pitch with box aspect matched to the data spans. cbar_scale
scales NES colorbar height (1 = default); the size legend stays stacked under it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axis. |
required |
on
|
str
|
Data level, |
'protein'
|
key_added
|
str
|
|
'pca_gsea'
|
pcs
|
list of int or None
|
1-based PCs to include; |
None
|
top_n
|
int
|
Cap on distinct pathways after ranking; must be >= 1. |
20
|
fdr_cutoff
|
float or None
|
Same meaning as in |
0.1
|
size_scale
|
float
|
Max bubble diameter as a fraction of the smaller cell pitch
(axes size in points divided by grid count). Default |
0.85
|
size_fdr_cap
|
float
|
Clip |
5.0
|
pc_pad
|
float
|
Half-spacing between PC columns in data units (also the x-edge margin).
Column centers are |
0.6
|
cbar_scale
|
float
|
Vertical scale for the NES colorbar relative to the default height
(default |
1.0
|
cmap
|
str or Colormap
|
Colormap for NES-centered coloring. |
'coolwarm'
|
title_case_labels
|
bool
|
If True, format pathway tick labels for display. |
True
|
force
|
bool
|
If True, re-run |
False
|
gsea_kwargs
|
dict or None
|
Forwarded to |
None
|
top_n_mode
|
str
|
|
'balanced'
|
include_pathways
|
str, iterable, or None
|
Keep only pathways matching these names. |
None
|
exclude_pathways
|
str, iterable, or None
|
Remove pathways matching these names. |
None
|
return_df
|
bool
|
If True, return |
False
|
Returns:
| Type | Description |
|---|---|
|
matplotlib.axes.Axes, or |
Example
Bubble chart for the first three PCs, top 25 pathways:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 8))
pdata.plot_pca_gsea_bubble(ax, pcs=[1, 2, 3], top_n=25)
Colorbar height via cbar_scale (0.5 / 1 / 1.5):
for scale in (0.5, 1.0, 1.5):
fig, ax = plt.subplots(figsize=(6, 8))
pdata.plot_pca_gsea_bubble(ax, pcs=[1, 2, 3], top_n=25, cbar_scale=scale)
Tighter bubbles, or allow more extreme FDR contrast in marker sizes:
fig, ax = plt.subplots(figsize=(6, 8))
pdata.plot_pca_gsea_bubble(
ax,
pcs=[1, 2, 3],
top_n=25,
size_scale=0.5, # smaller max diameter vs cell pitch
size_fdr_cap=10, # clip -log10(FDR) at 10 (FDR ≈ 1e-10)
)
Wider gaps between PC columns:
fig, ax = plt.subplots(figsize=(6, 8))
pdata.plot_pca_gsea_bubble(ax, pcs=[1, 2, 3], top_n=25, pc_pad=0.75)
Stricter FDR cutoff and title-case pathway labels:
Source code in src/scpviz/pAnnData/plot.py
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | |
plot_pca_gsea_heatmap
plot_pca_gsea_heatmap(
ax,
on="protein",
key_added="pca_gsea",
pcs=None,
top_n=30,
fdr_cutoff=0.1,
cmap="coolwarm",
title_case_labels=True,
force=False,
gsea_kwargs=None,
top_n_mode="balanced",
include_pathways=None,
exclude_pathways=None,
return_df=False,
)
Plot a pathway-by-principal-component heatmap of PCA-GSEA NES values.
Thin wrapper around :func:scpviz.plotting.plot_pca_gsea_heatmap.
Cell color is NES; optional top_n trimming uses the same FDR-aware scoring as the bubble plot.
Missing PCs in stored results produce NaN columns and a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axis. |
required |
on
|
str
|
Data level, |
'protein'
|
key_added
|
str
|
|
'pca_gsea'
|
pcs
|
list of int or None
|
1-based PCs as columns; |
None
|
top_n
|
int
|
Maximum pathways to retain after ranking; must be >= 1. |
30
|
fdr_cutoff
|
float or None
|
Same meaning as in |
0.1
|
cmap
|
str or Colormap
|
Heatmap colormap (diverging around zero is typical). |
'coolwarm'
|
title_case_labels
|
bool
|
If True, format pathway labels on the axis. |
True
|
force
|
bool
|
If True, re-run |
False
|
gsea_kwargs
|
dict or None
|
Forwarded to |
None
|
top_n_mode
|
str
|
|
'balanced'
|
include_pathways
|
str, iterable, or None
|
Keep only pathways matching these names. |
None
|
exclude_pathways
|
str, iterable, or None
|
Remove pathways matching these names. |
None
|
return_df
|
bool
|
If True, return |
False
|
Returns:
| Type | Description |
|---|---|
|
matplotlib.axes.Axes, or |
Example
Heatmap of NES for four PCs and the 40 top-ranked pathways:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5, 10))
pdata.plot_pca_gsea_heatmap(ax, pcs=[1, 2, 3, 4], top_n=40)
Diverging colormap with formatted pathway names on rows:
Source code in src/scpviz/pAnnData/plot.py
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
plot_pca_gsea_pathway_vectors
plot_pca_gsea_pathway_vectors(
ax,
on="protein",
key_added="pca_gsea",
plot_pc=[1, 2],
n_vectors=plotting.N_VECTORS_UNSET,
fdr_cutoff=0.1,
arrow_scale=0.25,
pca_kwargs=None,
show_samples=True,
title_case_labels=True,
force=False,
gsea_kwargs=None,
adjust_labels=True,
adjust_text_kwargs=None,
text_positions=None,
lock_text_positions=False,
top_n_mode="balanced",
exclude_pathways=None,
namelist=None,
cmap=None,
xlim=None,
ylim=None,
return_df=False,
)
Overlay PCA-GSEA pathways as arrows in a two-dimensional PCA sample space.
Thin wrapper around :func:scpviz.plotting.plot_pca_gsea_pathway_vectors.
Each arrow encodes normalized enrichment scores (NES) on two principal components taken from
adata.uns[key_added]['results'] (from pca_gsea). Arrow endpoints are rescaled using the
current axis limits so pathways remain visible; they are not plotted in the same numeric units as
sample coordinates. When show_samples is True, the sample PCA scatter is drawn first via
plot_pca.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axis (2D). |
required |
on
|
str
|
Data level, |
'protein'
|
key_added
|
str
|
|
'pca_gsea'
|
plot_pc
|
list of int
|
Exactly two 1-based PCs, e.g. |
[1, 2]
|
n_vectors
|
int, sequence, ``None``, or unset
|
Caps auto-selected pathways (after |
N_VECTORS_UNSET
|
fdr_cutoff
|
float or None
|
For auto-selected rows: pathway-level FDR filtering and score gating.
Namelist pathways skip the row FDR filter; a warning is printed per named pathway when
|
0.1
|
arrow_scale
|
float
|
Scale factor for arrow length relative to axis span. |
0.25
|
pca_kwargs
|
dict or None
|
Additional arguments passed to |
None
|
show_samples
|
bool
|
If True, plot samples first; if False, draw only axes, grid lines, and arrows. |
True
|
title_case_labels
|
bool
|
If True, format pathway labels for display (e.g. title case). |
True
|
force
|
bool
|
If True, re-run |
False
|
gsea_kwargs
|
dict or None
|
Forwarded to |
None
|
adjust_labels
|
bool
|
If True, run |
True
|
adjust_text_kwargs
|
dict or None
|
Extra keyword arguments for |
None
|
text_positions
|
dict or None
|
Optional manual label positions; keys are pathway raw or display
strings, values are |
None
|
lock_text_positions
|
bool
|
If True, labels with entries in |
False
|
top_n_mode
|
str
|
|
'balanced'
|
exclude_pathways
|
str, iterable, or None
|
Remove pathways matching these names (raw Term, short pathway, or library). |
None
|
namelist
|
list of str or None
|
Pathways to always include first. Shown even if they fail FDR;
|
None
|
cmap
|
dict or None
|
Per-pathway colors; lookup raw |
None
|
xlim
|
tuple or None
|
Applied after scatter / empty axes, before arrow scaling. |
None
|
ylim
|
tuple or None
|
Same as |
None
|
return_df
|
bool
|
If True, also return a DataFrame with NES, FDR, and label positions. |
False
|
Returns:
| Type | Description |
|---|---|
|
matplotlib.axes.Axes, or |
Example
Default overlay on PC1 vs PC2 with label de-cluttering:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax, vec_df = pdata.plot_pca_gsea_pathway_vectors(
ax,
plot_pc=[1, 2],
adjust_text_kwargs={"expand": (1.3, 1.3)},
return_df=True,
)
Reuse label positions from a previous run:
Source code in src/scpviz/pAnnData/plot.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
plot_pca_protein_vectors
plot_pca_protein_vectors(
ax,
on="protein",
plot_pc=(1, 2),
gene_col="Genes",
n_vectors=plotting.N_VECTORS_UNSET,
arrow_scale=0.25,
pca_kwargs=None,
show_samples=True,
title_case_labels=False,
adjust_labels=True,
adjust_text_kwargs=None,
text_positions=None,
lock_text_positions=False,
min_abs_loading_for_top_n=None,
top_n_mode="balanced",
exclude_genes=None,
namelist=None,
cmap=None,
xlim=None,
ylim=None,
return_df=False,
)
Overlay protein PCA loadings as arrows in a two-dimensional sample PCA space.
Thin wrapper around :func:scpviz.plotting.plot_pca_protein_vectors.
Arrows use feature loadings from adata.uns['pca']['PCs'] (from pAnnData.pca), not GSEA NES.
Geometry matches plot_pca_gsea_pathway_vectors: each arrow runs from the origin in the direction
(loading_on_PCx, loading_on_PCy), with length rescaled from the current axis limits for visibility.
Labels default to the gene_col column in .var when present, otherwise .var_names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axis (2D). |
required |
on
|
str
|
Data level, |
'protein'
|
plot_pc
|
tuple or list of int
|
Exactly two 1-based PCs. |
(1, 2)
|
gene_col
|
str
|
Column in |
'Genes'
|
n_vectors
|
int, sequence, ``None``, or unset
|
Caps auto-selected proteins (rows not already taken
by |
N_VECTORS_UNSET
|
arrow_scale
|
float
|
Scale factor for arrow length relative to axis span. |
0.25
|
pca_kwargs
|
dict or None
|
Forwarded to |
None
|
show_samples
|
bool
|
If True, draw the sample PCA scatter first; if False, only axes and arrows. |
True
|
title_case_labels
|
bool
|
If True, lightly format gene text (underscores to spaces, title case). |
False
|
adjust_labels
|
bool
|
If True, run |
True
|
adjust_text_kwargs
|
dict or None
|
Extra keyword arguments for |
None
|
text_positions
|
dict or None
|
Manual label positions keyed by gene or formatted label. |
None
|
lock_text_positions
|
bool
|
If True, manual positions are excluded from |
False
|
min_abs_loading_for_top_n
|
float or None
|
If set, ranking scores on a PC are zero when
|
None
|
top_n_mode
|
str
|
|
'balanced'
|
exclude_genes
|
str, iterable, or None
|
Remove genes/features matching these strings (gene label or
|
None
|
namelist
|
list of str or None
|
Gene labels (matrix row index, exact |
None
|
cmap
|
dict or None
|
Map gene label to a matplotlib color; lookup tries raw name, formatted label,
then case-insensitive keys. Default |
None
|
xlim
|
tuple or None
|
Applied after the PCA scatter and before arrow length scaling. |
None
|
ylim
|
tuple or None
|
Same stage as |
None
|
return_df
|
bool
|
If True, return |
False
|
Returns:
| Type | Description |
|---|---|
|
matplotlib.axes.Axes, or |
Example
Show top protein loadings on PC1 vs PC2 on sample PCA scatter:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(4, 4))
pdata.pca(on="protein")
pdata.plot_pca_protein_vectors(ax, n_vectors=10)
plt.show()

Top-loading genes with returned coordinates:
fig, ax = plt.subplots()
ax, vec = pdata.plot_pca_protein_vectors(
ax,
plot_pc=[1, 2],
n_vectors=25,
return_df=True,
)
Split-axis selection on PC1 and PC3:
fig, ax = plt.subplots()
pdata.plot_pca_protein_vectors(
ax,
plot_pc=[1, 3],
n_vectors=[5, 3],
adjust_labels=False,
)
Explicit genes with colors and axis limits:
fig, ax = plt.subplots()
pdata.plot_pca_protein_vectors(
ax,
plot_pc=[1, 2],
namelist=["TP53", "EGFR"],
cmap={"TP53": "crimson", "egfr": "steelblue"},
xlim=(-6, 6),
ylim=(-5, 5),
)
Loading arrows only (no sample points):
Source code in src/scpviz/pAnnData/plot.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | |
plot_rs
Visualize connectivity in the RS (protein × peptide) matrix.
Generates side-by-side histograms:
- Left: Number of peptides mapped to each protein
- Right: Number of proteins associated with each peptide
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figsize
|
tuple
|
Size of the matplotlib figure (default: (10, 4)). |
(10, 4)
|
Returns:
| Name | Type | Description |
|---|---|---|
out |
None
|
No return value; shows the figure interactively or closes it when using a non-interactive backend. |