scanpy sc.pl.scatter学习

# !mkdir data
# !wget http://cf.10xgenomics.com/samples/cell-exp/1.1.0/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz -O data/pbmc3k_filtered_gene_bc_matrices.tar.gz
# !cd data; tar -xzf pbmc3k_filtered_gene_bc_matrices.tar.gz
# !mkdir write

import numpy as np
import pandas as pd
import scanpy as sc

sc.settings.verbosity = 3             # verbosity: errors (0), warnings (1), info (2), hints (3)
sc.logging.print_header()
sc.settings.set_figure_params(dpi=80, facecolor='white')

results_file = 'write/pbmc3k.h5ad'  # the file that will store the analysis results

adata = sc.read_10x_mtx(
    'data/filtered_gene_bc_matrices/hg19/',  # the directory with the `.mtx` file
    var_names='gene_symbols',                # use gene symbols for the variable names (variables-axis index)
    cache=True)                              # write a cache file for faster subsequent reading

adata.var_names_make_unique()  # this is unnecessary if using `var_names='gene_ids'` in `sc.read_10x_mtx

adata

# preprocessing

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

sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)

adata.var['mt'] = adata.var_names.str.startswith('MT-')  # annotate the group of mitochondrial genes as 'mt'
sc.pp.calculate_qc_metrics(adata, qc_vars=['mt'], percent_top=None, log1p=False, inplace=True)

sc.pl.violin(adata, ['n_genes_by_counts', 'total_counts', 'pct_counts_mt'],
             jitter=0.4, multi_panel=True)

sc.pl.scatter(adata, x='total_counts', y='pct_counts_mt')
sc.pl.scatter(adata, x='total_counts', y='n_genes_by_counts')



# tips = sns.load_dataset('tips')

# sns.scatterplot(x='total_bill', y='tip',data=tips)

# tips

在这里插入图片描述而自己用seaborn实现

df1=adata.obs[["total_counts",'pct_counts_mt']]
import seaborn as sns
sns.scatterplot(data=df1,x="total_counts",y="pct_counts_mt")# 必须需要加入data=df1,不能直接传入df1 
## 这个scatter是一样的

在这里插入图片描述

其实sc.pl.scatter和sns.scatterplot()是一样的,并没有设么区别

`plt.scatter` 和 `ax.scatter` 都是用于绘制散点图的 Matplotlib 方法,它们之间的主要区别在于使用的对象和用法。 `plt.scatter` 是 Matplotlib 的顶层函数之一,它可以在当前图形中绘制散点图。如果您只想绘制一个简单的散点图,那么 `plt.scatter` 是一个很好的选择。它的用法非常简单,只需要将 x 和 y 数据传递给它即可。例如: ``` import matplotlib.pyplot as plt import numpy as np x = np.random.rand(50) y = np.random.rand(50) plt.scatter(x, y) plt.show() ``` `ax.scatter` 是在 Matplotlib 中 Axes 对象的方法,它允许您在特定的 Axes 对象中绘制散点图。如果您需要在一个图形中绘制多个子图,或者需要更精细地控制每个子图的属性,那么使用 `ax.scatter` 是更好的选择。例如: ``` import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() x = np.random.rand(50) y = np.random.rand(50) ax.scatter(x, y) plt.show() ``` 在这个例子中,我们首先创建一个新的 Figure 对象和一个 Axes 对象,并将它们存储在 fig 和 ax 变量中。然后,我们使用 ax.scatter() 方法在 Axes 对象上绘制散点图。这使我们可以更好地控制每个子图的属性,例如轴标签、标题、背景颜色等。最后,我们使用 plt.show() 方法显示图形。 总的来说,`plt.scatter` 是一个更简单的方法,适用于绘制单个散点图,而 `ax.scatter` 更适合于需要更多控制和更复杂图形的情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值