Python等高线图/热图

2024-04-19 12:04:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我在LoL比赛的df中有x和y坐标,我想创建一个等高线图或热图来显示球员在比赛中通常移动的位置。
有人知道我怎么做吗


Tags: df球员lol等高线图
2条回答
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import scipy
from scipy.stats.kde import gaussian_kde
from scipy import ndimage
from matplotlib import cm


#select the x and y coordinates
x = df['x']
y = df['y']
nbins= 512 
k = gaussian_kde(np.vstack([x,y]))
xi, yi = np.mgrid[0:512, 0:512] #size of the image/map in px
zi = k(np.vstack([xi.flatten(), yi.flatten()]))

im = mpimg.imread("map.png")#Put he background image


fig = plt.figure(figsize=(9,9))

ax2 = fig.add_subplot()



ax2.contourf(xi, yi, zi.reshape(xi.shape), alpha=0.5, cmap=cm.jet, extent=[1, -1, 1, -1])


ax2.set_xlim(0, 512)
ax2.set_ylim(0, 512)


ax2.axis('off')


plt.imshow(im, extent=[0, 512, 0, 512])
plt.savefig(f'Enemies/Clausura/{team}/{team} Stats/{summoner[1]} Early.png', dpi=None, bbox_inches='tight', pad_inches=0)

等高线图或热图需要3个值。必须提供x、y和z值才能绘制轮廓,因为x和y给出了位置,z给出了要将轮廓显示为x和y变量的变量的值

如果要显示播放器的运动随时间的变化,应查看matplotlib的动画。或者,如果你想显示“玩家密度场”,你必须计算它

相关问题 更多 >