# 稳稳吃鸡！用Python可视化分析 ”绝地求生1800万游戏数据“，

ID：datanami

### 1. 数据集描述

Kaggle datasets: PUBG Match Deaths and Statistics，

PUBG是第一个/第三人称射击游戏royale风格的游戏，与超过90名玩家在一个大岛上相遇，在这个大岛上，团队和玩家一直战斗直到死亡。玩家从飞机上空投到岛上，在那里他们将清除城镇和建筑物的武器，弹药，装甲和急救设备。然后玩家将决定与最后一个站立的终极目标战斗或隐藏。一个蓝色区域将在游戏中出现几分钟，通过对站在蓝色区域内的任何人造成伤害并阻止任何处于安全区域内的人员，将玩家拉近和靠近在一起。

### 2. 开场跳哪里，可以避免落地成盒？

```import pandas as pd
from scipy.ndimage.filters import gaussian_filter
import matplotlib.cm as cm
from matplotlib.colors import Normalize
import numpy as np
import matplotlib.pyplot as plt

# 先把玩家被击杀的数据导入
death = death_0.merge(death_1, how='outer')
print(death.shape)
# (18426348, 12)

# 筛选落地成盒的玩家(选取开局4分钟之内死亡的玩家)
in_240_seconds_erg = death.loc[(death['map'] == 'ERANGEL') & (death['time'] < 240), :].dropna()
in_240_seconds_mrm = death.loc[(death['map'] == 'MIRAMAR') & (death['time'] < 240), :].dropna()

data_erg = in_240_seconds_erg[['victim_position_x', 'victim_position_y']].values
data_mrm = in_240_seconds_mrm[['victim_position_x', 'victim_position_y']].values
data_erg = data_erg * 4096 / 800000
data_mrm = data_mrm * 1000 / 800000

def heatmap(x, y, s, bins=100):
heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins)
heatmap = gaussian_filter(heatmap, sigma=s)

extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
return heatmap.T, extent

hmap, extent = heatmap(data_erg[:, 0], data_erg[:, 1], 4.5)
alphas = np.clip(Normalize(0, hmap.max(), clip=True)(hmap) * 4.5, 0.0, 1.)
colors = Normalize(0, hmap.max(), clip=True)(hmap)
colors = cm.Reds(colors)
colors[..., -1] = alphas

fig, ax = plt.subplots(figsize=(24, 24))
ax.set_xlim(0, 4096)
ax.set_ylim(0, 4096)
ax.imshow(bg)
ax.imshow(colors, extent=extent, origin='lower', cmap=cm.Reds, alpha=0.9)
plt.gca().invert_yaxis()
plt.savefig('out1.png', dpi=100)

hmap, extent = heatmap(data_mrm[:, 0], data_mrm[:, 1], 4.5)
alphas = np.clip(Normalize(0, hmap.max(), clip=True)(hmap) * 4.5, 0.0, 1.)
colors = Normalize(0, hmap.max(), clip=True)(hmap)
colors = cm.Reds(colors)
colors[..., -1] = alphas

fig, ax = plt.subplots(figsize=(24, 24))
ax.set_xlim(0, 1000)
ax.set_ylim(0, 1000)
ax.imshow(bg)
ax.imshow(colors, extent=extent, origin='lower', cmap=cm.Reds, alpha=0.9)
plt.gca().invert_yaxis()
plt.savefig('out2.png', dpi=100)```

### 3. 哪里才是最佳吃鸡地点？

```last_seconds_erg = death.loc[(death['map'] == 'ERANGEL') & (death['killer_placement'] == 1), :].dropna()
last_seconds_mrm = death.loc[(death['map'] == 'MIRAMAR') & (death['killer_placement'] == 1), :].dropna()
data_erg = last_seconds_erg[['victim_position_x', 'victim_position_y']].values
data_mrm = last_seconds_mrm[['victim_position_x', 'victim_position_y']].values
data_erg = data_erg * 4096 / 800000
data_mrm = data_mrm * 1000 / 800000

hmap, extent = heatmap(data_erg[:, 0], data_erg[:, 1], 4.5)
alphas = np.clip(Normalize(0, hmap.max(), clip=True)(hmap) * 4.5, 0.0, 1.)
colors = Normalize(0, hmap.max(), clip=True)(hmap)
colors = cm.Reds(colors)
colors[..., -1] = alphas

fig, ax = plt.subplots(figsize=(24, 24))
ax.set_xlim(0, 4096)
ax.set_ylim(0, 4096)
ax.imshow(bg)
ax.imshow(colors, extent=extent, origin='lower', cmap=cm.Reds, alpha=0.9)
plt.gca().invert_yaxis()
plt.savefig('out3.png', dpi=100)

last_seconds_mrm = death.loc[(death['map'] == 'MIRAMAR') & (death['killer_placement'] == 1), :].dropna()
data_erg = last_seconds_erg[['victim_position_x', 'victim_position_y']].values
data_mrm = last_seconds_mrm[['victim_position_x', 'victim_position_y']].values
data_erg = data_erg * 4096 / 800000
data_mrm = data_mrm * 1000 / 800000

hmap, extent = heatmap(data_mrm[:, 0], data_mrm[:, 1], 4.5)
alphas = np.clip(Normalize(0, hmap.max(), clip=True)(hmap) * 4.5, 0.0, 1.)
colors = Normalize(0, hmap.max(), clip=True)(hmap)
colors = cm.Reds(colors)
colors[..., -1] = alphas

fig, ax = plt.subplots(figsize=(24, 24))
ax.set_xlim(0, 1000);
ax.set_ylim(0, 1000)
ax.imshow(bg)
ax.imshow(colors, extent=extent, origin='lower', cmap=cm.Reds, alpha=0.9)
plt.gca().invert_yaxis()
plt.savefig('out4.png', dpi=100)```

### 5. 远近战与吃鸡概率的关系

```last_seconds_erg = death.loc[(death['killer_placement'] == 1), :].dropna()

distance = np.sqrt(((last_seconds_erg['killer_position_x'] - last_seconds_erg['victim_position_x']) / 100) ** 2 + (
(last_seconds_erg['killer_position_y'] - last_seconds_erg['victim_position_y']) / 100) ** 2)
distance = distance.apply(lambda x: int(x))

labels = [0, 10, 30, 50, 100, 200, 500, 800, 1000, 1500, 2000, 3000, 5000, 10000, 20000]
distan_cut = pd.cut(distance, bins=labels)
distan_cut.value_counts().plot.bar(figsize=(10, 8))
plt.savefig('out6.png', dpi=100)```

### 6. 击杀数与吃鸡概率的关系

```match_stats = pd.read_csv('F:/pubg-match-deaths/aggregate/agg_match_stats_0.csv')
winer = match_stats.loc[(match_stats['team_placement'] == 1), :].dropna()
labels = [0, 2, 5, 8, 11, 15, 20, 30, 40, 50]
winer['kill'] = pd.cut(winer['player_kills'], bins=labels)
winer['assist'] = pd.cut(winer['player_assists'], bins=labels)
winer['kill'].value_counts().plot.bar(figsize=(10, 10))
plt.savefig('out7.png', dpi=100)```

*声明：推送内容及图片来源于网络，部分内容会有所改动，版权归原作者所有，如来源信息有误或侵犯权益，请联系我们删除或授权事宜。

- END -

1714 篇文章152 人订阅

0 条评论

## 相关文章

9300

14700

10500

15000

9000

15200

### 机器之心专访杨强教授：联邦迁移学习与金融领域的AI落地

7 月 21 日、22 日，由 KDD China 主办，西南交通大学和京东金融承办的 KDD Summer School 暨 KDD Pre-Conferen...

38510

8800

25000

10400