Visualization & Plotting

This module contains functions for visualizing Counter-Strike 2 demo files.

awpy.plot

Awpy plotting module.

awpy.plot.gif(map_name: str, frames_data: list[dict], output_filename: str, duration: int = 500, lower_points_frac: float | None = 0.4) None[source]

Create an animated gif from a list of frames.

Parameters:
  • map_name (str) – Name of the map to plot. E.g. “de_dust2” (“dust2” or “de_dust2.png” will not work).

  • frames_data (list[dict]) – list of dictionaries, each containing ‘points’ and ‘point_settings’ for a frame.

  • frames (list[Image.Image]) – list of PIL Image objects.

  • output_filename (str) – Name of the output GIF file.

  • duration (int) – Duration of each frame in milliseconds.

  • lower_points_frac (optional, float) –

    The factor by which to multiply the opacity of a given point if it is on the lower level of the map and map_name is NOT referencing the lower level (i.e. map_name does not end in “_lower”). Defaults to 0.4.

    If map_name is referencing the lower level of a map (i.e. ends in “_lower”) then this argument is ignored and lower points’ alpha is set to 1 and upper points’ alpha is set to 0.

awpy.plot.heatmap(map_name: str, points: list[tuple[float, float, float]], method: Literal['hex', 'hist', 'kde'], size: int = 10, cmap: str = 'RdYlGn', alpha: float = 0.5, *, alpha_range: list[float] | None = None, kde_lower_bound: float = 0.1) tuple[Figure, Axes][source]

Create a heatmap of points on a Counter-Strike map.

Parameters:
  • map_name (str) – Name of the map to plot. E.g. “de_dust2” (“dust2” or “de_dust2.png” will not work).

  • points (list[tuple[float, float, float]]) – list of points to plot.

  • method (Literal["hex", "hist", "kde"]) – Method to use for the heatmap.

  • size (int, optional) – Size of the heatmap grid. Defaults to 10.

  • cmap (str, optional) – Colormap to use. Defaults to ‘RdYlGn’.

  • alpha (float, optional) – Transparency of the heatmap. Defaults to 0.5.

  • alpha_range (list[float, float], optional) – When value is provided here, points’ transparency will vary based on the density, with min transparency of alpha_range[0] and max of alpha_range[1]. Defaults to None, meaning no variance of transparency.

  • kde_lower_bound (float, optional) – Lower bound for KDE density values. Defaults to 0.1.

Raises:

ValueError – Raises a ValueError if an invalid method is provided.

Returns:

Matplotlib Figure and Axes objects

Return type:

tuple[Figure, Axes]

awpy.plot.plot(map_name: str, points: list[tuple[float, float, float]] | None = None, lower_points_frac: float | None = 0.4, point_settings: list[PointSettings] | list[dict[str, Any]] | None = None) tuple[Figure, Axes][source]

Plot a Counter-Strike map with optional points.

Parameters:
  • map_name (str) – Name of the map to plot. E.g. “de_dust2” (“dust2” or “de_dust2.png” will not work).

  • points (list[tuple[float, float, float]], optional) – list of points to plot. Each point is (X, Y, Z). Defaults to None.

  • lower_points_frac (optional, float) –

    The factor by which to multiply the opacity of a given point if it is on the lower level of the map and map_name is NOT referencing the lower level (i.e. map_name does not end in “_lower”). Defaults to 0.4.

    If map_name is referencing the lower level of a map (i.e. ends in “_lower”) then this argument is ignored and lower points’ alpha is set to 1 and upper points’ alpha is set to 0.

  • point_settings (list[PointSettings], list[dict[str, Any]], optional) –

    list of PointSettings objects or dictionaries with settings for each point.

    Each dictionary should contain: - ‘marker’: str (default ‘o’) - ‘color’: str (default ‘red’) - ‘size’: float (default 10) - ‘hp’: int (0-100) - ‘armor’: int (0-100) - ‘direction’: tuple[float, float] (pitch, yaw in degrees) - ‘label’: str (optional)

Raises:
  • FileNotFoundError – Raises a FileNotFoundError if the map image is not found.

  • ValueError – Raises a ValueError if the number of points and point_settings don’t match.

Returns:

Matplotlib Figure and Axes objects.

Return type:

tuple[Figure, Axes]