简体   繁体   中英

How to Line Plot several columns in Seaborn?

I am exploring the FIFA data set. I would like to see on a single line plot how is the Wage influenced by the variables listed below. How could I achieve this with seaborn?

Composure
Marking
Penalties
Vision
Stamina

Wage should be on the Y axis, while the other attributes should be shown on the X axis. Each line on the plot should be represented by 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.

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:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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