简体   繁体   English

如何在 Seaborn 中排列 Plot 几列?

[英]How to Line Plot several columns in Seaborn?

I am exploring the FIFA data set.我正在探索FIFA 数据集。 I would like to see on a single line plot how is the Wage influenced by the variables listed below.我想在一行 plot 上查看Wage如何受下面列出的变量影响。 How could I achieve this with seaborn?我怎样才能用 seaborn 实现这一目标?

Composure
Marking
Penalties
Vision
Stamina

Wage should be on the Y axis, while the other attributes should be shown on the X axis.工资应该在Y轴上,而其他属性应该在X轴上显示。 Each line on the plot should be represented by Composure, Marking..etc. plot 上的每一行都应该用 Composure、Marking..etc 来表示。

Stacking one plot over the other is not clean and I don't get the legend, so this is bad way of reporting.将一个 plot 堆叠在另一个上不干净,我没有得到图例,所以这是一种不好的报告方式。

import seaborn as sns
sns.lineplot(x=data.Positioning, y=data.Wage)
sns.lineplot(x=data.Overall, y=data.Wage)
sns.lineplot(x=data.Penalties, y=data.Wage)

在此处输入图像描述

Did you ask something like this?你问过这样的事情吗?

import matplotlib.ticker as ticker

columns_plot = ['Composure', 'Marking', 'Penalties', 'Vision', 'Stamina']

fig, ax = plt.subplots(figsize=(14, 9))
ax.yaxis.set_major_formatter(ticker.EngFormatter())
for each in columns_plot:
    sns.lineplot(data = df_final, x = each, y = 'Wage', label = str(each), ci = None)
plt.legend()
plt.show()

Produces:生产: 在此处输入图像描述

2nd method, side by side:第二种方法,并排:

fig, axes = plt.subplots(1, 5, figsize=(23, 5), sharey=True)

columns_plot = ['Composure', 'Marking', 'Penalties', 'Vision', 'Stamina']

for i, each in enumerate(columns_plot):
    sns.lineplot(data = df_final, ax = axes[i], x = each, y = 'TransformedWage', ci = None, color = 'g')
plt.show()

Produces:生产:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM