我正在努力重现所提供图像中的可视化风格。看起来像散点图是用来显示数据点的。当我尝试创建类似的可视化效果时,所有位置都变得可见。我的目标是创建另一个散点图,其中具有较大的圆圈,在活动较多的区域呈现较深的红色阴影,在活动不太明显的区域呈现较浅的阴影。
我相信我需要实现一个阈值来选择性地显示数据点并避免显示所有数据点。谁能指导我如何实现与图中所示类似的可视化效果?
我的剧情:
我想要的剧情:
我的代码:
def plot_cumulative_heatmap(positions: List[Tuple[float, float]], map_name: str = "de_mirage", map_type: str = "original", dark: bool = False, titel: str = "Counter-Terrorist Attacking", isPistol: str = "Pistol Round") -> Literal[True]:
heatmap_fig, heatmap_axes = plot_map(map_name=map_name, map_type=map_type, dark=dark)
heatmap_data = []
for position in positions:
x, y = position
heatmap_data.append((x, y))
# Extract data for plotting
x, y = zip(*heatmap_data)
sns.scatterplot(x=x, y=y, color='red', s=5, ax=heatmap_axes, alpha=0.5)
heatmap_axes.set_title(f"{titel}\nTotal Positions: {len(positions)}\n{isPistol}", fontsize=14, weight="bold")
heatmap_axes.get_xaxis().set_visible(False)
heatmap_axes.get_yaxis().set_visible(False)
print("Heatmap saved.")
return True
以下方法为每个输入坐标对绘制大的透明圆圈。如果真实输入包含多个具有相同坐标的点,它们的透明度将会累加。
import matplotlib.pyplot as plt
import numpy as np
# create some dummy test data
np.random.seed(20240311)
x = np.random.randn(20, 25).cumsum(axis=1).ravel()
y = np.random.randn(20, 25).cumsum(axis=1).ravel()
filter = (np.abs(x) < 7) & (np.abs(y) < 7) & ((np.abs(x) > 5) | (np.abs(y) > 5))
x = x[filter]
y = y[filter]
fig, ax = plt.subplots()
fig.set_facecolor('black')
ax.set_aspect('equal', 'datalim')
ax.scatter(x, y, color='salmon', alpha=0.3, lw=0, s=500)
# draw rectangles representing the walls
ax.add_patch(plt.Rectangle((-7, -7), 14, 14, fc='none', ec='w', lw=2))
ax.add_patch(plt.Rectangle((-5, -5), 10, 10, fc='none', ec='w', lw=2))
ax.axis('off')
plt.show()