投篮 lock_创建NBA投篮图表

投篮 lock

Here I create shot charts depicting both shooting percentage and the number of shots taken at different court locations, similar to those produced on Austin Clemens’ website (http://www.austinclemens.com/shotcharts/).

在这里,我创建了镜头图,描绘了在不同球场位置的镜头命中率和镜头数量,类似于在奥斯丁·克莱门斯(Austin Clemens)的网站( http://www.austinclemens.com/shotcharts/ )上制作的那些图表。

To create the shooting charts, I looked to a post by Savvas Tjortjoglou (http://savvastjortjoglou.com/nba-shot-sharts.html). Savvas’ post is great, but his plots only depict the number of shots taken at different locations.

为了创建拍摄图表,我查看了Savvas Tjortjoglou的帖子( http://savvastjortjoglou.com/nba-shot-sharts.html )。 Savvas的帖子很棒,但他的情节仅描绘了在不同位置拍摄的照片数量。

I’m interested in both the number of shots AND the shooting percentage at different locations. This requires a little bit more work. Here’s how I did it.

我对不同位置的拍摄数量和拍摄百分比都感兴趣。 这需要更多的工作。 这是我的方法。

1
1
2
2
3
3

First, we have to acquire shooting data about each player. I retrieved the data from NBA.com’s API using code from Savvas Tjortjoglou’s post.

首先,我们必须获取有关每个玩家的射击数据。 我使用Savvas Tjortjoglou帖子中的代码从NBA.com的API中检索了数据。

I won’t show you the output of this function. If you’re interested in the details, I recommend Savvas Tjortjoglou’s post.

我不会向您显示此函数的输出。 如果您对这些细节感兴趣,我推荐Savvas Tjortjoglou的帖子。

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13

Next, we need to draw a basketball court which we can draw the shot chart on. This basketball court has to use the same coordinate system as NBA.com’s API. For instance, 3pt shots have to be X units from hoop and layups have to be Y units from the hoop. Again, I recycle code from Savvas Tjortjoglou (phew! figuring out NBA.com’s coordinate system would have taken me awhile).

接下来,我们需要绘制一个篮球场,我们可以在其中绘制投篮图。 该篮球场必须使用与NBA.com API相同的坐标系。 例如,3pt射击必须是篮筐的X单位,上篮次数必须是篮筐的Y单位。 同样,我从Savvas Tjortjoglou回收代码((!搞清楚NBA.com的坐标系会花我一段时间)。

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42

We want to create an array of shooting percentages across the different locations in our plot. I decided to group locations into evenly spaced hexagons using matplotlib’s hexbin function (http://matplotlib.org/api/pyplot_api.html). This function will count the number of times a shot is taken from a location in each of the hexagons.

我们想在绘图中的不同位置创建一系列的拍摄百分比。 我决定使用matplotlib的hexbin函数( http://matplotlib.org/api/pyplot_api.html )将位置分为均匀分布的六边形。 此功能将计算从每个六边形中的某个位置拍摄照片的次数。

The hexagons are evenly spaced across the xy grid. The variable “gridsize” controls the number of hexagons. The variable “extent” controls where the first hexagon and last hexagon are drawn (ordinarily the first hexagon is drawn based on the location of the first shot).

六边形在xy网格上均匀分布。 变量“ gridsize”控制六边形的数量。 变量“范围”控制绘制第一个六边形和最后一个六边形的位置(通常根据第一个镜头的位置绘制第一个六边形)。

Computing shooting percentages requires counting the number of made and taken shots in each hexagon, so I run hexbin once using all shots taken and once using only the location of made shots. Then I simply divide the number of made shots by taken shots at each location.

计算射击百分比需要计算每个六边形中已拍摄和已拍摄照片的数量,因此我使用所有已拍摄的照片并且仅使用已拍摄照片的位置来运行hexbin。 然后,我简单地将拍摄数量除以每个位置的拍摄数量。

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17

I really liked how Savvas Tjortjoglou included players’ pictures in his shooting charts, so I recycled this part of his code too. The picture will appear in the bottom right hand corner of the shooting chart

我真的很喜欢Savvas Tjortjoglou在他的射击图表中包含球员照片的方式,因此我也重复了他的代码的这一部分。 图片将出现在拍摄图的右下角

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9

I want to depict shooting percentage using a sequential colormap – more red circles = better shooting percentage. The “reds” colormap looks great, but would depict a 0% shooting percentage as white (http://matplotlib.org/users/colormaps.html), and white circles will not appear in my plots. I want 0% shooting to be slight pink, so below I modify the reds colormap.

我想使用顺序色图来描述拍摄百分比-更多的红色圆圈=更好的拍摄百分比。 “红色”颜色图看起来不错,但是可以将0%的拍摄百分比描述为白色( http://matplotlib.org/users/colormaps.html ),而白色圆圈不会出现在我的绘图中。 我希望0%的拍摄是略带粉红色,因此下面我修改了红色的配色。

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9

Okay, now lets put it all together. The large function below will use the functions above to create a shot chart depicting shooting percentage as the color of a circle (more red = better shooting %) and the number of shots as the size of a circle (larger circle = more shots). One note about the circle sizes, the size of a circle can increase until they start to overlap. When they start to overlap, I prevent them from growing.

好的,现在让我们把它们放在一起。 下面的大功能将使用上面的功能来创建拍摄图表,将拍摄百分比描述为一个圆圈的颜色(红色表示更好的拍摄百分比),拍摄数量描述为一个圆圈的大小(更大的圆圈=更多的镜头)。 关于圆的大小的一个说明,圆的大小可以增加直到它们开始重叠。 当它们开始重叠时,我阻止它们增长。

In this function, I compute the shooting percentages and number of shots at each location. Then I draw circles depicting the number of shots taken at that location (circle size) and the shooting percentage at that location (circle color).

在此功能中,我计算每个位置的拍摄百分比和拍摄数量。 然后,我绘制圆圈,描述在该位置拍摄的照片数量(圆圈大小)和在该位置拍摄的拍摄百分比(圆圈颜色)。

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37

Ok, thats it! Now, because I’m a t-wolves fan, I’ll output the shot charts of top 6 t-wolves in minutes this year.

好的,就是这样! 现在,因为我是t狼的粉丝,所以我将在今年的几分钟内输出前6只t狼的射程图。

1
1
2
2
3
3

1
1
2
2
3
3

1
1
2
2
3
3

1
1
2
2
3
3

1
1
2
2
3
3

1
1
2
2
3
3

翻译自: https://www.pybloggers.com/2015/12/creating-nba-shot-charts/

投篮 lock

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值