scanpy多张图绘制于一张
|Word Count:332|Reading Time:1mins|Post Views:
当我们一次有多个数据,而且我们想要使用scanpy绘制umap图,或是spatial图的时候,大多数人一次只是绘制一个umap图或是一个spatial图在一个png或是一个pdf上面,对于我们可视化来说可能并没有那么轻便,于是需要做一些调整,借助于matplotlib的内参,让我们可以较为轻松的绘制多张图在一张图上面。代码比较容易理解,详细代码如下:
1 2 3 4 5 6 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
| fig=plt.figure(figsize=(20,20))
for i in range(1,13): temp = adata[adata.obs['slices']==str(i)] csv = pd.read_csv('/data/work/04.Transfer/RCTD/Result/all_batch/1014/' + str(i) + '.csv',sep = ' ') temp.obs['celltype'] = csv.first_type.tolist() axs = fig.add_subplot(4, 3, i) sc.pl.spatial(temp, color = 'celltype', spot_size = 40, ax = axs, show = False, title = 'Slice_' + str(i) + '_celltype', frameon = False, legend_fontsize ='x-small', legend_fontweight = 'normal', )
plt.savefig('all_batch_RCTD_TRANSFER.png') plt.close()
fig=plt.figure(figsize=(20,12))
for i in range(1,41): temp = adata[adata.obs['batch']==str(i)] axs = fig.add_subplot(4, 10, i) sc.pl.umap(temp, color = 'leiden', size = 2, ax = axs, show = False, title = 'Slice' + str(i), frameon = False, legend_loc = None, )
plt.savefig('figure/all_batch_harmony_leiden_umap.png') plt.close()
|
这里面也有对于边框,对于字体的一些调整,其他的参数大家可以看matplotlib的详细内参。