Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Seaborn绘制多个子图,每个子图显示熊猫数据帧的两列之间的关系_Python_Pandas_Dataframe_Seaborn - Fatal编程技术网

Python 使用Seaborn绘制多个子图,每个子图显示熊猫数据帧的两列之间的关系

Python 使用Seaborn绘制多个子图,每个子图显示熊猫数据帧的两列之间的关系,python,pandas,dataframe,seaborn,Python,Pandas,Dataframe,Seaborn,我有一只熊猫如下: 数据帧{'depth':[499500501502503],'parameter1':[25,29,24,23,25],'parameter2':[72,80,65,64,77]} 我希望在同一个图下绘制多个两个seaborn线形图,作为子图。 我希望在x轴上保持深度参数不变,但根据其他列值改变y轴参数 sns.relplotx='depth',y=parameter1,kind='line',data=df sns.relplotx='depth',y=parameter2

我有一只熊猫如下:

数据帧{'depth':[499500501502503],'parameter1':[25,29,24,23,25],'parameter2':[72,80,65,64,77]}

我希望在同一个图下绘制多个两个seaborn线形图,作为子图。 我希望在x轴上保持深度参数不变,但根据其他列值改变y轴参数

sns.relplotx='depth',y=parameter1,kind='line',data=df

sns.relplotx='depth',y=parameter2,kind='line',data=df

我曾尝试使用seaborn.FaceGrid,但没有获得正确的结果

让我知道如何将这些图绘制为单个图下的子图,而不必单独定义它们。

要使用FaceGrid,必须使用melt将数据帧转换为长格式

请注意,使用relplot而不是手动创建FacetGrid可以更简单地实现相同的输出

要使用FacetGrid,您必须使用melt转换长格式的数据帧

请注意,使用relplot而不是手动创建FacetGrid可以更简单地实现相同的输出

如果使用熊猫打印是一个选项,则此选项将起作用:

df.plot(x= 'depth', layout=(1,2),subplots=True, sharey=True, figsize=(10,4))
plt.show()
输出:

此外,如果您愿意,可以在顶部添加seaborn样式:

sns.set_style('darkgrid')
df.plot(x= 'depth', layout=(1,2),subplots=True,sharey=True, figsize=(10.5,4))
plt.show()
输出:

如果使用熊猫打印是一个选项,则此选项将起作用:

df.plot(x= 'depth', layout=(1,2),subplots=True, sharey=True, figsize=(10,4))
plt.show()
输出:

此外,如果您愿意,可以在顶部添加seaborn样式:

sns.set_style('darkgrid')
df.plot(x= 'depth', layout=(1,2),subplots=True,sharey=True, figsize=(10.5,4))
plt.show()
输出:

sns.relplot是FacetGrid。sns.relplot是FacetGrid。