还在用散点图展示UMAP吗?最近读到一篇有意思的文章,作者把二维细胞图谱画成了起伏的“山峦”:哪里细胞更集中,山峰就更突出。我们用公开数据GSE226314试了一遍,得到3D密度山峦图和2D密度等高线图。本文保留全部代码,从论文原图、数据到绘图结果,按顺序分享。

图1|研究原文Figure 2;本文借鉴的是其中B小图的3D密度景观。来源:Yang R 等,The Innovation,2026,7(6):101274(DOI: 10.1016/j.xinn.2026.101274)[1]

01 论文里的UMAP,竟然有“山峰”

灵感来自《The Innovation》论文”HBV-driven expansion of CXCR6+-exhausted T cells and CXCL16+ macrophage interaction: Implications for immunotherapy in HCC“。[1]其中Figure 2B将HBV与非HBV组的UMAP局部密度绘成三维地形。山高与红蓝颜色对应估计概率密度,并非基因表达量。

02 换一套数据:GSE226314

演示数据GSE226314来自2023年《Nature Cardiovascular Research》的一项心脏功能恢复研究[2]。原文Figure 1b给出了185,881个细胞核的UMAP,涵盖心肌细胞、成纤维细胞、髓系细胞等。不同细胞群在UMAP中位置清楚,适合检验三维密度山峦的可视化效果。

图2|GSE226314对应研究的原文Figure 1;B小图展示细胞类型UMAP。来源:Amrute JM 等,Nature Cardiovascular Research,2023,2(4):399–416(DOI: 10.1038/s44161-023-00260-8)[2]

03 先画回常规UMAP

我们先按细胞名称复现原文中的常规UMAP,它既能检查坐标和细胞注释,也是后续两张密度图共同使用的二维底图。

基于GSE226314重新绘制的细胞类型UMAP
图3|基于GSE226314重新绘制的细胞类型UMAP

04 3D画法:把UMAP变成“山峦”

把所有细胞的UMAP坐标落到网格上,经高斯滤波得到联合核密度(joint KDE),再用密度作为三维表面的高度。脚本还会添加细胞群的彩色山脚和标签。下面是生成山峦图的完整Python代码,可输出PNG和PDF。

完整代码①|3D密度山峦图

输入的数据为已包含细胞类型注释和降维信息的AnnData;输出文件为PNG和PDF。

#加载所需的包
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
from scipy.ndimage import gaussian_filter
from matplotlib.colors import LinearSegmentedColormap, Normalize
from matplotlib.cm import ScalarMappable
from matplotlib.ticker import MaxNLocator, ScalarFormatter
from mpl_toolkits.mplot3d import proj3d
#输出路径
outdir = Path("./Plots/KDEplot/")
outdir.mkdir(parents=True, exist_ok=True)
#数据
adata = GSE226314_global
celltype_col = "cell.type"
#细胞群配色
celltype_colors = {"Adipocyte": "#939BC5", "Cardiomyocyte": "#E5002B", "Endocardium": "#24245F", "Endothelium": "#238438", "Epicardium": "#84358C", "Fibroblast": "#F36B19", "Glia": "#F5DF22", "Lymphatic": "#B45A9E", "Mast": "#CB974D", "Myeloid": "#83CBD9", "Pericyte": "#80BF4D", "SMC": "#EF7B86", "TNKCells": "#8B70AD"}
#使用完整网格,避免抽样漏掉高密度尖峰
grid_n = 540
surface_step = 1
#带宽按UMAP较短轴跨度计算,也可手动设置bandwidth_umap
bandwidth_umap = None
bandwidth_fraction = 0.0035
truncate = 4.0
#山体尾部裁剪
surface_cut = 0.010
#有效密度网格的99%分位数作为颜色上限,超过上限统一显示红色
color_quantile = 0.99
#底部彩色基底
footprint_bandwidth_factor = 2.5
footprint_cut = 0.035
footprint_alpha = 0.42
#山体高度与观察角度
mountain_height = 0.42
view_elev = 42
view_azim = -65
#分段密度配色,设为256可恢复连续渐变
density_color_steps = 22
background = "#FFFCF3"
label_fs = 11
label_alpha = 0.88
base_offset_fraction = 0.015
#标签位置:base为山脚,peak为山体上方
label_position = "base"
#标签显示名称
label_names = {"Adipocyte": "Adipocytes", "Cardiomyocyte": "Cardiomyocytes", "Endocardium": "Endocardium", "Endothelium": "Endothelial cells", "Epicardium": "Epicardium", "Fibroblast": "Fibroblasts", "Glia": "Glia", "Lymphatic": "Lymphatics", "Mast": "Mast cells", "Myeloid": "Myeloid", "Pericyte": "Pericytes", "SMC": "Smooth muscle", "TNKCells": "T/NK cells"}
#标签偏移单位points,例如{"Cardiomyocyte": (15, -5), "Fibroblast": (-15, 6)}
label_offsets = {}
#保存设置
save_png = True
save_pdf = True
output_prefix = "GSE226314_joint_UMAP_ridge_landscape"
#密度色带:浅蓝→深蓝黑→红色
density_cmap = LinearSegmentedColormap.from_list("ridge_density", [(0.00, "#F0F8F5"), (0.10, "#DDEFF0"), (0.25, "#B8DCE5"), (0.40, "#8BBCCF"), (0.55, "#6098B4"), (0.68, "#365F86"), (0.78, "#292E52"), (0.86, "#571E45"), (0.93, "#E81D43"), (1.00, "#FF263E")], N=density_color_steps)
#检查输入
if celltype_col not in adata.obs.columns: raise KeyError(f"adata.obs 中不存在列:{celltype_col}")
if "X_umap" not in adata.obsm: raise KeyError('adata.obsm 中不存在 "X_umap",请先计算UMAP')
if not 0 < color_quantile <= 1: raise ValueError("color_quantile必须大于0且不超过1")
if not 0 < surface_cut < 1: raise ValueError("surface_cut必须在0和1之间")
xy_all = np.asarray(adata.obsm["X_umap"], dtype=float)
if xy_all.ndim != 2 or xy_all.shape[1] < 2: raise ValueError("X_umap必须至少包含两列")
xy_all = xy_all[:, :2]
#过滤缺失标签和无效坐标,不修改原始adata
ct_series = adata.obs[celltype_col].astype("string").str.strip()
valid_ct = (ct_series.notna() & ~ct_series.str.lower().isin({"", "na", "nan", "none", "<na>"})).fillna(False).to_numpy(dtype=bool)
valid = valid_ct & np.isfinite(xy_all).all(axis=1)
xy = xy_all[valid]
ct_values = ct_series[valid].astype(str).to_numpy()
if len(xy) < 2: raise ValueError("有效细胞数量不足")
span = np.ptp(xy, axis=0)
if np.any(span <= 0): raise ValueError("UMAP两个坐标轴均需要非零跨度")
cts = list(pd.unique(ct_values))
missing_colors = [ct for ct in cts if ct not in celltype_colors]
if missing_colors: raise ValueError(f"以下细胞群尚未设置配色:{missing_colors}")
#确定KDE带宽
bandwidth = float(bandwidth_umap) if bandwidth_umap is not None else float(span.min() * bandwidth_fraction)
if not np.isfinite(bandwidth) or bandwidth <= 0: raise ValueError("bandwidth必须是大于0的有限数值")
#网格范围
padding = np.maximum(span * 0.04, bandwidth * footprint_bandwidth_factor * truncate)
xmin, ymin = xy.min(axis=0) - padding
xmax, ymax = xy.max(axis=0) + padding
xedges = np.linspace(xmin, xmax, grid_n + 1)
yedges = np.linspace(ymin, ymax, grid_n + 1)
xgrid = (xedges[:-1] + xedges[1:]) / 2
ygrid = (yedges[:-1] + yedges[1:]) / 2
dx = xedges[1] - xedges[0]
dy = yedges[1] - yedges[0]
X, Y = np.meshgrid(xgrid, ygrid, indexing="xy")
sigma = (bandwidth / dy, bandwidth / dx)
if min(sigma) < 1: print("提示:带宽小于一个网格间距,建议增大grid_n以提高密度估计精度")
#二维计数直方图
def histogram_counts(points):
    hist, _, _ = np.histogram2d(points[:, 0], points[:, 1], bins=(xedges, yedges))
    return hist.T.astype(float)
#全部有效细胞共同计算joint KDE
H = histogram_counts(xy)
Z = gaussian_filter(H, sigma=sigma, truncate=truncate, mode="constant", cval=0.0)
Z /= Z.sum() * dx * dy
density_max = float(Z.max())
base_z = -density_max * base_offset_fraction
#颜色范围独立于山体高度,避免少量极高尖峰压低整体颜色
visible_density = Z[Z >= density_max * surface_cut]
color_vmax = float(np.quantile(visible_density, color_quantile))
norm = Normalize(vmin=0.0, vmax=color_vmax, clip=True)
print(f"有效细胞数:{len(xy):,} | 细胞群:{len(cts)}")
print(f"KDE bandwidth:{bandwidth:.5f}")
print(f"真实最大密度:{density_max:.6f} | 颜色饱和上限:{color_vmax:.6f}")
print(f"Density integral:{Z.sum() * dx * dy:.6f}")
#每个细胞群的底部色块与标签锚点
ct_footprints = {}
label_positions = {}
footprint_sigma = tuple(s * footprint_bandwidth_factor for s in sigma)
for ct in cts:
    Hct = histogram_counts(xy[ct_values == ct])
    Zct = gaussian_filter(Hct, sigma=footprint_sigma, truncate=truncate, mode="constant", cval=0.0)
    ct_footprints[ct] = Zct
    iy, ix = np.unravel_index(np.argmax(Zct), Zct.shape)
    pz = Z[iy, ix] + density_max * 0.025 if label_position == "peak" else base_z
    label_positions[ct] = (xgrid[ix], ygrid[iy], pz)
#完整网格山体,保留真实密度高度
row_idx = np.unique(np.r_[np.arange(0, grid_n, surface_step), grid_n - 1])
col_idx = np.unique(np.r_[np.arange(0, grid_n, surface_step), grid_n - 1])
Xs = X[np.ix_(row_idx, col_idx)]
Ys = Y[np.ix_(row_idx, col_idx)]
Zs = Z[np.ix_(row_idx, col_idx)].copy()
Zs[Zs < density_max * surface_cut] = np.nan
#直接生成表面颜色,避免默认面片平均高度着色削弱尖峰颜色
surface_facecolors = density_cmap(norm(np.nan_to_num(Zs, nan=0.0)))
surface_facecolors[..., 3] = np.where(np.isfinite(Zs), 1.0, 0.0)
#画布
fig = plt.figure(figsize=(12, 9), facecolor=background)
ax = fig.add_axes([0.005, 0.015, 0.86, 0.97], projection="3d", facecolor=background)
ax.set_proj_type("ortho")
ax.view_init(elev=view_elev, azim=view_azim)
#保持UMAP横纵坐标相同比例
xspan = xmax - xmin
yspan = ymax - ymin
planar_scale = max(xspan, yspan)
ax.set_box_aspect((1.25 * xspan / planar_scale, 1.25 * yspan / planar_scale, mountain_height))
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
ax.set_zlim(base_z, density_max * 1.08)
ax.set_axis_off()
ax.grid(False)
#彩色基底
footprint_order = sorted(cts, key=lambda ct: np.count_nonzero(ct_footprints[ct] >= ct_footprints[ct].max() * footprint_cut), reverse=True)
for ct in footprint_order:
    Zct = ct_footprints[ct]
    local_max = float(Zct.max())
    if local_max <= 0: continue
    ax.contourf(X, Y, Zct, levels=[local_max * footprint_cut, local_max * 1.001], zdir="z", offset=base_z, colors=[celltype_colors[ct]], alpha=footprint_alpha, antialiased=True)
#joint KDE山体,关闭额外光照以保持密度色带颜色
surface = ax.plot_surface(Xs, Ys, Zs, facecolors=surface_facecolors, rstride=1, cstride=1, linewidth=0, edgecolor="none", antialiased=False, shade=False)
surface.set_zsort("average")
surface.set_rasterized(True)
#圆角细胞群标签
annotations = {}
for ct in cts:
    x2, y2, _ = proj3d.proj_transform(*label_positions[ct], ax.get_proj())
    default_offset = (0, -3) if label_position == "base" else (0, 4)
    annotation = ax.annotate(label_names.get(ct, ct), xy=(x2, y2), xycoords="data", xytext=label_offsets.get(ct, default_offset), textcoords="offset points", ha="center", va="center" if label_position == "base" else "bottom", fontsize=label_fs, color="white", bbox={"boxstyle": "round,pad=0.30,rounding_size=0.80", "facecolor": celltype_colors[ct], "edgecolor": "none", "alpha": label_alpha}, annotation_clip=False, zorder=1000)
    annotations[ct] = annotation
#更新标签投影
def update_label_projection():
    projection = ax.get_proj()
    for ct, annotation in annotations.items():
        x2, y2, _ = proj3d.proj_transform(*label_positions[ct], projection)
        annotation.xy = (x2, y2)
#交互旋转后同步标签
def on_mouse_release(event):
    if event.inaxes is ax:
        update_label_projection()
        fig.canvas.draw_idle()
callback_id = fig.canvas.mpl_connect("button_release_event", on_mouse_release)
#右侧颜色条,顶部使用平头延伸表示超过颜色上限的密度
cax = fig.add_axes([0.89, 0.22, 0.020, 0.56])
sm = ScalarMappable(norm=norm, cmap=density_cmap)
sm.set_array([])
cb = fig.colorbar(sm, cax=cax, extend="max" if color_vmax < density_max else "neither", extendrect=True)
cb.set_label("Probability Density", fontsize=12, labelpad=10, color="#252525")
cb.locator = MaxNLocator(nbins=7)
formatter = ScalarFormatter(useMathText=True)
formatter.set_powerlimits((-3, 3))
cb.formatter = formatter
cb.update_ticks()
cb.ax.tick_params(labelsize=10, colors="#252525", width=0.8, length=4)
cb.outline.set_edgecolor("#444444")
cb.outline.set_linewidth(0.9)
cax.set_facecolor(background)
#更新绘图
fig.canvas.draw()
update_label_projection()
#保存PNG
if save_png:
    png_path = outdir / f"{output_prefix}.png"
    fig.savefig(png_path, dpi=400, bbox_inches="tight", pad_inches=0.10, facecolor=background)
    print(f"PNG已保存:{png_path.resolve()}")
#保存PDF
if save_pdf:
    pdf_path = outdir / f"{output_prefix}.pdf"
    fig.savefig(pdf_path, dpi=350, bbox_inches="tight", pad_inches=0.10, facecolor=background)
    print(f"PDF已保存:{pdf_path.resolve()}")
#显示
plt.show()
GSE226314的3D联合密度山峦图
图4|GSE226314的3D联合密度山峦图。峰高与山体颜色编码UMAP上的局部概率密度,彩色山脚辅助标识细胞类型

高密度区域显示为红色。bandwidth_fraction决定平滑程度,surface_cut裁掉低密度尾部,color_quantile调整颜色饱和阈值,但不会改变实际山峰高度。

05 2D画法:热图+细胞群等密度线

如果担心3D视角遮挡细节,可以把密度摊回二维平面。底色是所有细胞的联合密度,白线表示整体等密度线,彩色轮廓突出各细胞群的空间分布。完整代码如下,它和3D版使用同一份UMAP坐标,但带宽、网格和颜色归一化不同,因此不要直接比较两图色条数值。

完整代码②|2D联合密度图

同样使用GSE226314_global,绘制联合热图与各细胞群的彩色等密度线。

#加载所需的包
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
from scipy.ndimage import gaussian_filter
from matplotlib.colors import LinearSegmentedColormap, Normalize
from matplotlib.cm import ScalarMappable
#输出路径
outdir = Path("./Plots/KDEplot/")
outdir.mkdir(parents=True, exist_ok=True)
#数据,不按年龄或样本类型分组
adata = GSE226314_global
celltype_col = "cell.type"
#细胞群配色
celltype_colors = {"Adipocyte": "#939BC5", "Cardiomyocyte": "#E5002B", "Endocardium": "#24245F", "Endothelium": "#238438", "Epicardium": "#84358C", "Fibroblast": "#F36B19", "Glia": "#F5DF22", "Lymphatic": "#B45A9E", "Mast": "#CB974D", "Myeloid": "#83CBD9", "Pericyte": "#80BF4D", "SMC": "#EF7B86", "TNKCells": "#8B70AD"}
#参数
grid_n = 300
bandwidth_umap = 0.75
truncate = 3.0
label_fs = 11
heat_cut = 0.015
#细胞群等密度线参数
contour_width = 2.0
contour_alpha = 0.8
contour_levels = [0.10, 0.25, 0.45, 0.65]
#全体细胞等密度线参数
joint_contour_width = 0.4
joint_contour_alpha = 0.22
joint_contour_number = 10
#标签偏移,单位UMAP坐标,例如{"Fibroblast": (-0.5, 0.3)}
label_offsets = {}
#保存名称
save_name = "GSE226314_JointUMAPDensity_All"
#密度配色:浅蓝→深蓝黑→红色
cmap = LinearSegmentedColormap.from_list("density_cmap", [(0.00, "#F0F8F5"), (0.10, "#DDEFF0"), (0.25, "#B8DCE5"), (0.40, "#8BBCCF"), (0.55, "#6098B4"), (0.68, "#365F86"), (0.78, "#292E52"), (0.86, "#571E45"), (0.93, "#E81D43"), (1.00, "#FF263E")], N=256)
cmap = cmap.copy()
cmap.set_bad((1, 1, 1, 0))
#检查输入
if celltype_col not in adata.obs.columns: raise KeyError(f"adata.obs 中不存在列:{celltype_col}")
if "X_umap" not in adata.obsm: raise KeyError('adata.obsm 中不存在 "X_umap"')
if bandwidth_umap <= 0: raise ValueError("bandwidth_umap必须大于0")
xy_all = np.asarray(adata.obsm["X_umap"], dtype=float)
if xy_all.ndim != 2 or xy_all.shape[1] < 2: raise ValueError("X_umap必须至少包含两列")
xy_all = xy_all[:, :2]
#清理标签,不修改原始adata
ct_series = adata.obs[celltype_col].astype("string").str.strip()
valid_ct = (ct_series.notna() & ~ct_series.str.lower().isin({"", "na", "nan", "none", "<na>"})).fillna(False).to_numpy(dtype=bool)
#全部有效UMAP坐标参与joint KDE,缺失细胞群标签的细胞不绘制分类轮廓
valid_xy = np.isfinite(xy_all).all(axis=1)
xy = xy_all[valid_xy]
ct_values = ct_series.fillna("").to_numpy(dtype=str)[valid_xy]
ct_valid = valid_ct[valid_xy]
if len(xy) < 2: raise ValueError("有效UMAP坐标数量不足")
cts = list(pd.unique(ct_values[ct_valid]))
missing_colors = [ct for ct in cts if ct not in celltype_colors]
if missing_colors: raise ValueError(f"以下细胞群尚未设置配色:{missing_colors}")
#坐标范围,预留高斯核尾部空间
span = np.ptp(xy, axis=0)
if np.any(span <= 0): raise ValueError("UMAP两个坐标轴均需要非零跨度")
padding = np.maximum(span * 0.05, bandwidth_umap * truncate)
xmin, ymin = xy.min(axis=0) - padding
xmax, ymax = xy.max(axis=0) + padding
#使用直方图bin中心作为绘图网格,保证热图与轮廓对齐
xedges = np.linspace(xmin, xmax, grid_n + 1)
yedges = np.linspace(ymin, ymax, grid_n + 1)
xgrid = (xedges[:-1] + xedges[1:]) / 2
ygrid = (yedges[:-1] + yedges[1:]) / 2
dx = xedges[1] - xedges[0]
dy = yedges[1] - yedges[0]
X, Y = np.meshgrid(xgrid, ygrid, indexing="xy")
sigma = (bandwidth_umap / dy, bandwidth_umap / dx)
#计算二维概率密度
def compute_density(points):
    H, _, _ = np.histogram2d(points[:, 0], points[:, 1], bins=(xedges, yedges))
    Z = gaussian_filter(H.T.astype(float), sigma=sigma, truncate=truncate, mode="constant", cval=0.0)
    total = Z.sum()
    if total > 0: Z /= total * dx * dy
    return Z
#全部细胞的joint KDE
Z = compute_density(xy)
density_max = float(Z.max())
Z_show = np.ma.masked_less(Z, density_max * heat_cut)
norm = Normalize(vmin=0, vmax=density_max)
#每个细胞群的密度轮廓与标签位置
ct_density = {}
label_pos = {}
for ct in cts:
    pts = xy[ct_valid & (ct_values == ct)]
    if len(pts) == 0: continue
    Zct = compute_density(pts)
    if Zct.max() <= 0: continue
    ct_density[ct] = Zct
    iy, ix = np.unravel_index(np.argmax(Zct), Zct.shape)
    offset_x, offset_y = label_offsets.get(ct, (0, 0))
    label_pos[ct] = (xgrid[ix] + offset_x, ygrid[iy] + offset_y)
#画布
fig, ax = plt.subplots(figsize=(11, 9), facecolor="white")
fig.subplots_adjust(left=0.03, right=0.84, top=0.92, bottom=0.04)
#全体细胞密度热图,保持UMAP坐标等比例
ax.imshow(Z_show, origin="lower", extent=[xmin, xmax, ymin, ymax], cmap=cmap, norm=norm, aspect="equal", interpolation="nearest", zorder=1)
#白色joint KDE等密度线
joint_levels = np.linspace(density_max * 0.10, density_max * 0.95, joint_contour_number)
joint_levels = joint_levels[(joint_levels > Z.min()) & (joint_levels < Z.max())]
if len(joint_levels) > 0: ax.contour(X, Y, Z, levels=joint_levels, colors="#FFFFFF", linewidths=joint_contour_width, alpha=joint_contour_alpha, zorder=2)
#细胞群彩色等密度线
for ct in cts:
    if ct not in ct_density: continue
    Zct = ct_density[ct]
    levels = np.array(contour_levels) * Zct.max()
    levels = np.unique(levels[(levels > Zct.min()) & (levels < Zct.max())])
    if len(levels) == 0: continue
    ax.contour(X, Y, Zct, levels=levels, colors=[celltype_colors[ct]], linewidths=contour_width, alpha=contour_alpha, zorder=3)
#细胞群标签
for ct, (px, py) in label_pos.items():
    ax.text(px, py, ct, fontsize=label_fs, fontweight="bold", color="#263746", ha="center", va="center", zorder=4)
#坐标与标题
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
ax.set_aspect("equal", adjustable="box")
ax.set_axis_off()
ax.set_title("All cells", fontsize=18, fontweight="bold", pad=12)
#概率密度颜色条
sm = ScalarMappable(norm=norm, cmap=cmap)
sm.set_array([])
cax = fig.add_axes([0.88, 0.18, 0.025, 0.64])
cbar = fig.colorbar(sm, cax=cax)
cbar.set_label("Probability density", fontsize=14, color="#657788")
cbar.ax.tick_params(labelsize=11, colors="#718394")
cbar.outline.set_edgecolor("#D0D7DE")
#输出信息
print(f"参与joint KDE的细胞数:{len(xy):,}")
print(f"有效细胞群数量:{len(cts)}")
print(f"Maximum probability density:{density_max:.6f}")
#保存PNG和PDF
png_path = outdir / f"{save_name}.png"
pdf_path = outdir / f"{save_name}.pdf"
fig.savefig(png_path, dpi=600, bbox_inches="tight", facecolor="white")
fig.savefig(pdf_path, bbox_inches="tight", facecolor="white")
print(f"PNG已保存:{png_path.resolve()}")
print(f"PDF已保存:{pdf_path.resolve()}")
#显示
plt.show()
plt.close(fig)
2D联合密度热图叠加细胞类型轮廓线
图5|2D联合密度热图叠加细胞类型轮廓线。底色是全体细胞的密度,彩色线条提示不同细胞群的空间范围。

这里各细胞群轮廓按本群的峰值归一化,适合看群体位置和形状,不能直接用来比较不同细胞类型的绝对数量。

06 复用代码前,记住这几点

3D适合展示密度的高低起伏,2D更方便比较空间轮廓和相邻位置。两种图各有侧重,可以与普通UMAP搭配使用。两版脚本的缺失标签筛选略有不同:3D要求标签和坐标都有效;2D的联合热图纳入所有有效坐标。做定量对照时请统一筛选规则。

还要注意:UMAP距离不是组织中的物理距离,山峰和等密度线也不能直接证明细胞相互作用或统计显著性。一张UMAP,换两种视角。希望这两套代码能给你的单细胞绘图带来一点新灵感。

参考资料

[1] Yang R, Lu C, Jian Q, et al. HBV-driven expansion of CXCR6+-exhausted T cells and CXCL16+ macrophage interaction: Implications for immunotherapy in HCC. The Innovation 2026;7(6):101274. DOI: 10.1016/j.xinn.2026.101274

[2] Amrute JM, Lai L, Ma P, et al. Defining cardiac functional recovery in end-stage heart failure at single-cell resolution. Nature Cardiovascular Research 2023;2(4):399–416. DOI: 10.1038/s44161-023-00260-8