0

I have a dataframe of footballers and their premier league fantasy football stats, I would like to create line plots for each player (x-axis: gameDate, y-axis: points)

Below is a def I created that filters the dataframe based on the player name and attempts the lineplot.

def PlotPlayerPoints(df, player):
    df = df.copy()
    df = df.filter(like=player, axis=0)
    
    plt.figure(figsize=(20,6))
    plt.title(player)
    sns.lineplot(data=ffmlDf, x="gameDate", y="points", estimator=None)
        
for player in ffmlDf['playerName'].unique():
    PlotPlayerPoints(ffmlDf, player)
    

The lineplot comes through as the exact same for each player, so my attempt at filtering clearly did not work.

1 Answer 1

2

I think you are looking for a hue parameter. Showing your df would help.

import pandas as pd
import seaborn as sns

df = sns.load_dataset('tips')
sns.lineplot(x='total_bill', y='size', hue='sex', data=df)

hue acts like a filter and draws the selected plot for each instance found in the hue parameter, so in your case hue would need to be the player.

enter image description here

Unless you want n lineplots for each player then, of course, you can use for loop.

Sign up to request clarification or add additional context in comments.

2 Comments

Hello Mate thanks for the speedy reply. I created a google document to show screenshots of the dataframe and me using hue. I thought about using hue before but as there are 460 premier league players, it becomes very congested. google docs link: docs.google.com/document/d/…
Try to add your data to the original question in a form of code, if not possible a screenshot will do. If you have too many players, you can sort your df by a selected metric or group by a club and then plot n lineplots showing players per club or just top n players by y metric. In general, lineplot with 460 lines is not desirable. Try to show what is important, not everything or further summarise the data by grouping of filtering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.