1 回答
TA贡献1812条经验 获得超5个赞
您可以melt使用 DataFrame 并将结果变量用作style分组:
from io import StringIO
import numpy as np
import pandas as pd
import seaborn as sns
data = """index x-axis col1 col2 group group2
0 0 27 26 A C
1 1 45 27 B D
2 2 48 22 A C
3 3 35 24 B D
4 4 49 38 A C
5 5 46 29 B D
6 6 29 37 A C
7 7 38 41 B D
8 8 24 46 A C
9 9 46 38 B D
10 10 37 23 A C"""
df = pd.read_csv(StringIO(data), index_col=[0], sep=" ", skipinitialspace=True)
sns.relplot(
data=df.melt(id_vars=["x-axis", "group", "group2"], value_vars=["col1", "col2"]),
x="x-axis", y="value", style="variable", hue="group", col="group2", kind="line")
输出:
添加回答
举报