[英]Scatter Plot Binary Data Color Coded Points from Data Labels
I'd like to use matplotlib.pyplot.scatter to create a scatter plot similar to the picture below from data in a dataframe with a header that is formatted similar to the table here where all the points for a given sample are colored based on the label 在數據的第一列中,僅針對值為 1 的每個基因繪制一個點 - 對於值為 0 的基因沒有點:
label | 基因a | b基因 | 基因 c | 基因d |
---|---|---|---|---|
1 | 0 | 1 | 0 | 0 |
0 | 1 | 1 | 0 | 1 |
0 | 0 | 0 | 1 | 0 |
1 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 0 | 0 |
注意:我的樣本數據與我的樣本散點圖 plot output 不匹配。
將 dataframe 融化為長格式后,您可以使用 seaborn 的sns.relplot
繪制矩陣
import pandas as pd
import seaborn as sns
sns.set_style("ticks")
df = pd.read_html('https://stackoverflow.com/q/70856944/14277722')[0]
df['sample'] = df.index
df = df.melt(['label','sample'])
g = sns.relplot(
data=df,
x="variable", y="sample", hue="label", size="value",
hue_norm=(-1, 1), palette='tab10',
height=6, sizes=(10, 300), size_norm=(0, 1)
)
g.set(xlabel="Genes", ylabel="Samples");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.