Python等高线图/热图

Python等高线图/热图,python,heatmap,contourf,Python,Heatmap,Contourf,我在LoL比赛的df中有x和y坐标,我想创建一个等高线图或热图来显示球员在比赛中通常移动的位置。 有人知道我该怎么做吗?等高线图或热图需要3个值。必须提供x、y和z值才能绘制轮廓,因为x和y给出了位置,z给出了要将轮廓显示为x和y变量的变量的值 如果要显示播放器的运动随时间的变化,应查看matplotlib的动画。或者,如果你想显示“玩家密度场”,你必须计算它。等高线图或热图需要3个值。必须提供x、y和z值才能绘制轮廓,因为x和y给出了位置,z给出了要将轮廓显示为x和y变量的变量的值 impor

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

有人知道我该怎么做吗?

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


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

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

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)

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

这已经为LoL比赛做了,基于此,你可以检查它。这已经为LoL比赛做了,基于此,你可以检查它。我不需要动画,如何计算玩家密度场?例如,您可以创建一个网格,并计算网格中每个正方形的玩家数量,每个正方形的密度为N层/平方面积。你将得到一个2d数组,你只能用它来显示。Matshow我不需要动画,我如何计算玩家密度场?例如,你可以创建一个网格,并计算网格中每个正方形的玩家数量,每个正方形的密度将是nLayers/squareArea。最终将得到一个只能使用.matshow显示的二维数组
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)