python具有唯一z值的多个x与y线图
我有一个熊猫数据框,看起来像这样:python具有唯一z值的多个x与y线图,python,pandas,matplotlib,bokeh,Python,Pandas,Matplotlib,Bokeh,我有一个熊猫数据框,看起来像这样: Iteration output Temperature 1 23 -40 1 26 -7 1 20 25 1 30 78 2 34 -40 2
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()
谢谢!这是一个非常优雅的解决方案。接下来,如何获得每个线条图对应的迭代数?@lonely请参见编辑。。。应该添加图例条目(在调用
show
之前,您可能需要使用plt.legend()
启用图例。非常感谢。现在获得图例了。