python 具有唯一 z 值的多个 x 与 y 线图
python multiple x vs y line plots with unique z values
我有一个 pandas 数据框,如下所示:
Iteration output Temperature
1 23 -40
1 26 -7
1 20 25
1 30 78
2 34 -40
2 33 -7
2 32 25
2 36 78
3 34 -40
3 37 -7
3 45 25
3 43 78
我想为唯一迭代值获取输出 (y) 与温度 (x) 的多条线图。
对于示例数据,我会得到三个重叠线图,用于三个唯一的迭代值。
如何在 python 中执行此操作?
我是否获得了唯一迭代值的列表,然后使用它来过滤数据框并单独绘制它们?
for group,records in df.groupby('iteration'):
plt.plot(records['output'],records['temperature'],legend=str(group))
我可能会这样做
以下应该有效:
import seaborn as sns
import matplotlib.pyplot as plt
g=sns.FacetGrid(df, row='Iteration')
g=g.map(plt.scatter, 'Temperature', 'output')
plt.show()
如果你想要在同一个情节中的3条线,这是代码:
import seaborn as sns
import matplotlib.pyplot as plt
sns.lineplot(df['Temperature'], df['output'], hue=df['Iteration'])
plt.show()
我有一个 pandas 数据框,如下所示:
Iteration output Temperature
1 23 -40
1 26 -7
1 20 25
1 30 78
2 34 -40
2 33 -7
2 32 25
2 36 78
3 34 -40
3 37 -7
3 45 25
3 43 78
我想为唯一迭代值获取输出 (y) 与温度 (x) 的多条线图。
对于示例数据,我会得到三个重叠线图,用于三个唯一的迭代值。
如何在 python 中执行此操作?
我是否获得了唯一迭代值的列表,然后使用它来过滤数据框并单独绘制它们?
for group,records in df.groupby('iteration'):
plt.plot(records['output'],records['temperature'],legend=str(group))
我可能会这样做
以下应该有效:
import seaborn as sns
import matplotlib.pyplot as plt
g=sns.FacetGrid(df, row='Iteration')
g=g.map(plt.scatter, 'Temperature', 'output')
plt.show()
如果你想要在同一个情节中的3条线,这是代码:
import seaborn as sns
import matplotlib.pyplot as plt
sns.lineplot(df['Temperature'], df['output'], hue=df['Iteration'])
plt.show()