'Plot line chart with Matplotlib
I want to plot the probability of any 'shotType' being a goal as 'shotDistance' increases. Plotting probability of a shot being a goal based on 'shotType' as 'shotDistance' increases. I want the y-axis to be a percent of 0 to 1 based on value of '%total' and the x-axis to be 'shotDistance' min to 'shotDistance' max - roughly 0 to 100. My I don't have really any experience with matplotlib besides plotting lines and histograms with simple datasets. Not sure where to start.
My code:
allPlayerShotStats =shots.groupby(['shotType','shotDistance','event'])['event'].agg(['count'])
allPlayerShotStats['%total'] =allPlayerShotStats.groupby(['shotDistance','event'])['count'].apply(lambda x: x / sum(x))
allPlayerShotStats
Returns:
shotType shotDistance event count %total
0 BACK 1.000000 GOAL 3 0.214286
1 BACK 1.000000 SHOT 1 0.142857
2 BACK 1.414214 GOAL 6 0.206897
3 BACK 1.414214 MISS 1 0.166667
4 BACK 1.414214 SHOT 4 0.137931
... ... ... ... ... ...
25240 WRIST 97.169954 SHOT 4 0.444444
25241 WRIST 97.508974 SHOT 1 1.000000
25242 WRIST 97.575612 SHOT 8 0.571429
25243 WRIST 97.989795 GOAL 1 1.000000
25244 WRIST 97.989795 SHOT 4 0.800000
I've been playing around with various techniques but I'm not knowledgeable enough to really know what I'm doing with matplotlib.
In
plt.plot(allPlayerShotStats["shotDistance"].values, allPlayerShotStats["%total"].values)
Out
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

