Plots#
2D Visualization Module#
This module provides visualization tools for analyzing and understanding the dynamics of agents and resource distributions in 2D domains for influencer games. It includes utilities for plotting agent positions, influence distributions, and bifurcation dynamics in 2D rectangular domains.
The module is designed to work with the InflGame.adaptive subpackage and supports creating visual representations of agent behaviors and resource distributions in 2D environments.
Usage:#
The functions in this module can be used to visualize agent dynamics and resource distributions in 2D domains. For example, the dist_and_pos_plot_2d_simple function can be used to plot agent positions over time and their influence distributions.
Functions
- InflGame.domains.two_d.two_plots.agent_density_3d_2d(pos_matrix, num_agents, domain_bounds, bins=25, distance_threshold=0.05, cmap='viridis', font={'cbar_size': 16, 'default_size': 15, 'font_family': 'sans-serif', 'legend_size': 12, 'title_size': 18}, figsize=(24, 20), xlabel='$x_1$', ylabel='$x_2$', zlabel='Number of Agents', axis_return=False, edgecolor='black', linewidth=0.2, alpha=0.9, title_ads=[], save=False, name_ads=[], save_types=['.png', '.svg'], paper_figure={'figure_id': 'agent_density_3d', 'paper': False, 'section': 'A'}, id=0, cap_z_axis=True, integer_ticks=True)#
Create a 3D histogram showing agent density at final positions for 2D rectangular domain.
- Parameters:
- pos_matrixnp.ndarray or torch.Tensor
Position matrix of shape (time_steps, num_agents, 2).
- num_agentsint
Number of agents.
- domain_boundsnp.ndarray
Domain bounds of shape (2, 2) as [[x_min, x_max], [y_min, y_max]].
- binsint
Number of bins in each dimension.
- distance_thresholdfloat
Distance threshold for clustering nearby agents.
- cmapstr
Colormap name.
- fontdict
Font configuration dictionary.
- figsizetuple
Figure size as (width, height).
- xlabelstr
Label for x-axis.
- ylabelstr
Label for y-axis.
- zlabelstr
Label for z-axis.
- axis_returnbool
If True, return axes object; if False, return figure object.
- edgecolorstr
Color of outlines around bars.
- linewidthfloat
Width of bar edge lines.
- alphafloat
Bar transparency.
- title_adslist
Additional titles for the plot.
- savebool
Whether to save the plot.
- name_adslist
Additional names for saved files.
- save_typeslist
File types to save the plot.
- paper_figuredict
Dictionary for paper figure naming.
- idint
Identifier for file naming.
- cap_z_axisbool
If True, cap the z-axis maximum at num_agents.
- integer_ticksbool
If True, only show integer ticks on the z-axis.
- Returns:
- matplotlib.figure.Figure
The generated plot figure.
- InflGame.domains.two_d.two_plots.dist_and_pos_plot_2d_simple(num_agents, bin_points, cmap1, cmap2, pos_matrix, infl_dist, resource_type, x_min=None, y_min=None, domain_bounds=None, resources=0, font={'cbar_size': 12, 'default_size': 12, 'font_family': 'sans-serif', 'legend_size': 12, 'sub_title_size': 12, 'title_size': 14})#
Plots the positions of agents over time and their influence distributions.
- Parameters:
- num_agentsint
Number of agents.
- bin_pointsnp.ndarray
Points representing resource bins (
N x 2).- cmap1Any
Colormap for agent positions.
- cmap2Any
Colormap for influence distributions.
- pos_matrixtorch.Tensor
Tensor containing agent positions over time.
- infl_disttorch.Tensor
Tensor containing influence distributions.
- resource_typestr
Type of resource distribution.
- x_minfloat, optional
Optional lower x bound for the plot window.
- y_minfloat, optional
Optional lower y bound for the plot window.
- domain_boundstorch.Tensor, optional
Optional domain bounds tensor for axis limits.
- resourcestorch.Tensor, optional
Resource values over bins, defaults to 0.
- fontdict, optional
Font sizing / family dictionary for the figure.
- Returns:
- matplotlib.figure.Figure
The generated plot figure.
- InflGame.domains.two_d.two_plots.dist_plot_2d(agent_id, infl_dist, rect_Y, rect_X, font)#
Plots the influence distribution of a single agent.
- Parameters:
- agent_idint
ID of the agent.
- infl_disttorch.Tensor
Tensor containing influence distributions.
- rect_Ynp.ndarray
Y-coordinates of the rectangular grid.
- rect_Xnp.ndarray
X-coordinates of the rectangular grid.
- Returns:
- matplotlib.figure.Figure
The generated plot figure.
- InflGame.domains.two_d.two_plots.equilibrium_bifurcation_plot_2d_simple(num_agents, domain_bounds, reach_num_points, final_pos_matrix, title_ads, font={'cbar_size': 12, 'default_size': 12, 'font_family': 'sans-serif', 'legend_size': 12, 'title_size': 14})#
Plots the bifurcation of agents’ final positions for different parameter values.
- Parameters:
- num_agentsint
Number of agents.
- domain_boundsnp.ndarray
Bounds of the domain.
- reach_num_pointsint
Number of points in the reach.
- final_pos_matrixtorch.Tensor
Tensor containing final positions of agents.
- title_adslist
Additional strings to append to the plot title.
- Returns:
- matplotlib.figure.Figure
The generated plot figure.
- InflGame.domains.two_d.two_plots.pos_plot_2d(num_agents, pos_matrix, domain_bounds, title_ads=[], font={'cbar_size': 12, 'default_size': 12, 'font_family': 'sans-serif', 'legend_size': 12, 'title_size': 14}, axis_return=False, line_thickness=2, marker_size=8, black=False, fig_size=(18, 18))#
Plot agent position trajectories over time in a 2D domain.
Creates a plot showing how agent positions change over gradient ascent iterations in a 2D space. Each agent’s trajectory is plotted as a separate line with a distinct color. Start positions are marked with open circles and end positions with filled circles.
- Parameters:
- num_agentsint
Number of agents in the simulation.
- pos_matrixtorch.Tensor
Matrix of agent positions over time (shape: [time_steps, num_agents, 2]).
- domain_boundsnp.ndarray
Bounds of the 2D domain as [[x_min, x_max], [y_min, y_max]].
- title_adsOptional[list]
Additional strings to append to the plot title.
- fontdict
Font configuration dictionary with keys: ‘default_size’, ‘cbar_size’, ‘title_size’, ‘legend_size’, ‘font_family’.
- axis_returnOptional[bool]
If True, return axes object; if False, return figure object.
- line_thicknessfloat
Thickness of trajectory lines.
- marker_sizefloat
Size of start/end markers.
- Returns:
- matplotlib.figure.Figure
The generated matplotlib figure or axes object.