mba*_*hin 2 pandas line-plot seaborn facet-grid
这是针对我的问题的最小、完整和可验证的玩具数据集:
genes = pd.Series(["Gene1"] * 16 + ["Gene2"] * 16)
conditions = pd.Series(np.tile(np.array(["Condition1"] * 8 + ["Condition2"] * 8), 2))
wellID = pd.Series(np.array(["W1"] * 4 + ["W2"] * 4 + ["W3"] * 4 + ["W4"] * 4 + ["W5"] * 4 + ["W6"] * 4 + ["W7"] * 4 + ["W8"] * 4))
fluo = pd.Series(np.array([np.sort(np.random.logistic(size=4)) for _ in range(8)]).flatten())
cycles = pd.Series(np.tile(np.array([0, 1, 2, 3]), 8))
df = pd.concat([genes, conditions, wellID, cycles, fluo], axis=1)
df.columns = ["Gene", "Condition", "WellID", "Cycle", "Fluo"]
Run Code Online (Sandbox Code Playgroud)
它由用于 2 个条件的 2 个基因组成,每个基因有 2 个重复(1 个重复具有 1 个独特的 WellID,其中有 4 个循环,每个循环测量 1 个荧光点)。
我可以使用以下命令创建我想要隔离一个基因的线图:
sns.lineplot(x="Cycle", y="Fluo", hue="Condition", units="WellID", estimator=None, data=df.loc[df.Gene == "Gene1"])
Run Code Online (Sandbox Code Playgroud)
我必须同时使用单位和估计器,以便我可以看到 2 个重复(而不是每个基因/条件的聚合曲线。
最后,我想使用 FacetGrid 查看 2 个基因的图,所以我做了:
g = sns.FacetGrid(df, col="Gene", hue="Condition", col_wrap=5)
g.map(sns.lineplot, "Cycle", "Fluo");
Run Code Online (Sandbox Code Playgroud)
但是如果我有关键字“units”和“estimator”,我就会有一个错误说“ ValueError:无法解释输入'WellID' ”。
我只能显示聚合了 2 个重复的图。
将其作为参数传递给 lineplot 函数
g = sns.FacetGrid(df, col="Gene", hue="Condition", col_wrap=5)
g.map(sns.lineplot, "Cycle","Fluo", "WellID")
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3199 次 |
| 最近记录: |