import os
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/ProgramData/Anaconda3/Library/plugins/platforms'
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")
import wget
file = "~Philadelphia Flyers CSV.csv"
path = "U:/"
import os
size = os.stat('~Philadelphia Flyers CSV.csv').st_size
I gathered stats from the 2010-2011 NHL Philadelphia Flyers, such as their goals, assists, average time on ice, and much more.
This scatterplot shows the total shots made on goal for each player, compared to the percentage of goals actually made. Each point represents a specific player.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
import plotly.graph_objects as go
warnings.filterwarnings("ignore")
path = "U:/"
filename = "~Philadelphia Flyers CSV.csv"
df = pd.read_csv(path + filename, skiprows=3)
plt.figure(figsize=(20, 10))
plt.scatter(df['S'], df['S%'])
plt.title('Shots on Goal compared to Goals Made Percentage', fontsize=12)
plt.xlabel('Shots on Goal', fontsize=10)
plt.ylabel('Percentage of Shots Scored', fontsize=10)
plt.mode='markers+text'
plt.show()
This histogram depicts the average shifts on ice, which is the average number of times the player is on ice per game, not the number of minutes they are on the ice. This describes the number of times they are subbed on and off the ice throughout a game.
plt.figure(figsize=(20, 10))
plt.bar(df.loc[0:26, 'Players'], df.loc[0:26, 'SFT/G'], label='Average Number of Times on Ice per game')
plt.legend(loc='upper right', fontsize=5)
plt.show()
This pie chart shows the distribution ofwhich position each player on the team is, depicting Center, Left Wing, Right Wing, and Defense.
import pandas as pd
import matplotlib.pyplot as plt
data = {'Position': ['R', 'C', 'C', 'C', 'L', 'L', 'L', 'D', 'D', 'D', 'D', 'R', 'R', 'D', 'C', 'D', 'C', 'R', 'L', 'L', 'L', 'C', 'D', 'D', 'D', 'D', 'D']}
df2 = pd.DataFrame(data)
position_counts = df2['Position'].value_counts()
plt.pie(position_counts.values, labels=position_counts.index, autopct='%1.1f%%')
plt.title("Pie Chart of Players' Positions")
plt.show()
## Donut Chart of Penalty minutes based on Position This donut chart
shows the distribution of total penalty minutes among the different
positions on ice.
my_df = [['Position', 'PIM']]
pie_df = df[['Position', 'PIM']].groupby(['Position']).agg({'Position':'count', 'PIM':'sum'}).rename(columns={'Position': 'Count', 'PIM': 'PIM_Sum'}).reset_index(drop=False)
import seaborn as sns
fig = plt.figure(figsize=(20, 20))
ax = fig.add_subplot(1, 1, 1)
plt.pie(pie_df.Count,
labels = pie_df.Position,
pctdistance=0.85,
autopct='%1.1f%%',
wedgeprops = {"edgecolor" : "white",
'linewidth': 2,
'antialiased': True},
textprops = {'fontsize':20},
colors=sns.color_palette('Set2'),
frame=True,
radius=1,
startangle=90)
plt.pie(pie_df.PIM_Sum,
pctdistance=0.70,
autopct='%1.1f%%',
wedgeprops={"edgecolor": "white",
'linewidth':2},
textprops = {'fontsize':20},
radius=0.7,
startangle=90)
hole=plt.Circle((0,0), 0.2,
fc='white')
fig1=plt.gcf()
fig1.gca().add_artist(hole)
plt.show()
data = {'X': [51, 34, 30, 43, 34, 25, 19, 39, 31, 24, 21, 6, 11, 17, 10, 14, 7, 4, 2, 2, 1, 0, 0, 0, 0, 0, 0],
'Y': [25, 34, 36, 23, 19, 24, 21, 1, 6, 8, 4, 16, 11, 1, 7, 2, 5, 7, 4, 2, 0, 0, 0, 0, 0, 0, 0]}
df4 = pd.DataFrame(data)
plt.plot(df4['X'], df4['Y'], marker = 'o', linestyle='-', color='orange', label='Line Plot')
plt.xlabel('Assists')
plt.ylabel('Goals')
plt.title('Assists vs Goals for Each Player')
plt.show()
## Conclusion Thank you for exploring these visualizations!