Visualization
This module contains functions for visualization.
awpy.visualization.plot
Functions for plotting player positions and nades.
Example:
from awpy.visualization.plot import plot_round
plot_round(
"best_round_ever.gif",
d["gameRounds"][7]["frames"],
map_name=d["mapName"],
map_type="simpleradar",
dark=False,
)
https://github.com/pnxenopoulos/awpy/blob/main/examples/02_Basic_CSGO_Visualization.ipynb
- awpy.visualization.plot.plot_frame_map_control(map_name: str, frame: GameFrame, plot_type: Literal['default', 'players'] = 'default', given_fig_ax: tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes] | tuple[None, None] = (None, None)) tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes] [source]
Visualize map control for awpy frame.
- Parameters:
map_name (str) – Map used position_transform call
frame (GameFrame) – awpy frame to calculate map control for
plot_type (MapControlPlotType) – Determines which type of plot is created (either default or with players)
given_fig_ax – Optional tuple containing figure and ax objects for plotting
- Returns:
matplotlib fig and ax
- Raises:
ValueError – If map_name is not in awpy.data.NAV
- awpy.visualization.plot.plot_map(map_name: str = 'de_dust2', map_type: str = 'original', *, dark: bool = False) tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes] [source]
Plots a blank map.
- Parameters:
map_name (str, optional) – Map to search. Defaults to “de_dust2”
map_type (str, optional) – “original” or “simpleradar”. Defaults to “original”
dark (bool, optional) – Only for use with map_type=”simpleradar”. Indicates if you want to use the SimpleRadar dark map type Defaults to False
- Returns:
matplotlib fig and ax
- awpy.visualization.plot.plot_map_control_metrics(metric_arr: list[float]) tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes] [source]
Function to plot given map control metrics.
- Parameters:
metric_arr (list) – List containing map control values to plot
- Returns:
matplotlib fig and ax with map control metric plot
- Raises:
ValueError – If metrics is empty
- awpy.visualization.plot.plot_nades(rounds: list[awpy.types.GameRound], nades: list[str] | None = None, side: str = 'CT', map_name: str = 'de_ancient', map_type: str = 'original', *, dark: bool = False) tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes] [source]
Plots grenade trajectories.
- Parameters:
rounds (list) – List of round objects from a parsed demo
nades (list, optional) – List of grenade types to plot Defaults to []
side (str, optional) – Specify side to plot grenades. Either “CT” or “T”. Defaults to “CT”
map_name (str, optional) – Map to search. Defaults to “de_ancient”
map_type (str, optional) – “original” or “simpleradar”. Defaults to “original”
dark (bool, optional) – Only for use with map_type=”simpleradar”. Indicates if you want to use the SimpleRadar dark map type. Defaults to False
- Returns:
matplotlib fig and ax
- awpy.visualization.plot.plot_positions(positions: list[awpy.types.PlotPosition], map_name: str = 'de_ancient', map_type: str = 'original', *, dark: bool = False, apply_transformation: bool = False) tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes] [source]
Plots player positions.
- Parameters:
positions (list[PlotPosition]) – List of lists of plot positions containing: position (tuple[float, float]): Tuple of length 2 ([[x,y], …]) color (str): Color for the position marker (str): Marker for the position alpha (float): Alpha value for the position sizes (float): Size for the position
map_name (str, optional) – Map to search. Defaults to “de_ancient”
map_type (str, optional) – “original” or “simpleradar”. Defaults to “original”
dark (bool, optional) – Only for use with map_type=”simpleradar”. Indicates if you want to use the SimpleRadar dark map type Defaults to False
apply_transformation (bool, optional) – Indicates if you need to also use position_transform() for the X/Y coordinates, Defaults to False
- Returns:
matplotlib fig and ax
- awpy.visualization.plot.plot_round(filename: str, frames: list[awpy.types.GameFrame], map_name: str = 'de_ancient', map_type: str = 'original', *, dark: bool = False, fps: int = 10) Literal[True] [source]
Plots a round and saves as a .gif.
CTs are blue, Ts are orange, and the bomb is an octagon. Only use untransformed coordinates.
- Parameters:
filename (str) – Filename to save the gif
frames (list) – List of frames from a parsed demo
map_name (str, optional) – Map to search. Defaults to “de_ancient”
map_type (str, optional) – “original” or “simpleradar”. Defaults to “original
dark (bool, optional) – Only for use with map_type=”simpleradar”. Indicates if you want to use the SimpleRadar dark map type Defaults to False
fps (int, optional) – Number of frames per second in the gif Defaults to 10
- Returns:
True, saves .gif
- awpy.visualization.plot.plot_round_map_control(filename: str, map_name: str, round_data: GameRound, plot_type: Literal['default', 'players'] = 'default') Literal[True] [source]
Create gif summarizing map control for round.
- Parameters:
filename (str) – Filepath to save the gif to file
map_name (str) – Map used in plot_frame_map_control call
round_data (GameRound) – Round whose map control will be animated. Expected format that of awpy round
plot_type (MapControlPlotType) – Determines which type of plot is created (either with or without players)
- Returns:
True, ensuring function has completed
- Raises:
ValueError – If map_name is not in awpy.data.NAV
]
- awpy.visualization.plot.position_transform(map_name: str, position: float, axis: Literal['x', 'y']) float [source]
Transforms an X or Y coordinate.
- Parameters:
map_name (str) – Map to search
position (float) – X or Y coordinate
axis (str) – Either “x” or “y” (lowercase)
- Returns:
float
- Raises:
ValueError – Raises a ValueError if axis not ‘x’ or ‘y’