Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

python - 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)

enter image description here

question from:https://stackoverflow.com/questions/65942070/how-to-line-plot-several-columns-in-seaborn

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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: enter image description here

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:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...