hari_plotter.plotter module

class hari_plotter.plotter.Plotter(interfaces: Interface | list[Interface] | None = None)[source]

Bases: object

class PlotLattice(size_ratios: tuple[list[float], list[float]] = ([1.0], [1.0]), figsize=None)[source]

Bases: object

axs() list[list[Axes]][source]

Get the axes objects.

Returns: list[list[Axes]]: The axes objects.

convert_parameters_to_index(column: int, row: int) tuple[int, int][source]

Convert the column and row indices to the corresponding index in the axes list.

Parameters: column (int): The column index. row (int): The row index.

Returns: tuple[int, int]: The corresponding index in the axes list.

create_fig_and_axs() tuple[Figure, Axes][source]

Create the figure and axes objects.

Returns: tuple[Figure, Axes]: The figure and axes objects.

fig() Figure[source]

Get the figure object.

Returns: Figure: The figure object.

fig_axs() tuple[Figure, list[list[Axes]]][source]

Get the figure and axes objects.

Returns: tuple[Figure, list[list[Axes]]]: The figure and axes objects.

get_ax_by_index(index: tuple[int, int]) Axes[source]

Get the axes object based on the given index.

Parameters: index (tuple[int, int]): The index in the axes list.

Returns: Axes: The axes object.

get_figsize() tuple[float, float][source]

Get the figure size. If a size was set during initialization, it returns that size. Otherwise, it calculates the size based on the sum of size_ratios.

Returns: tuple[float, float]: The size of the figure as (height, width).

property num_cols: int

Get the number of columns in the lattice.

Returns: int: The number of columns.

property num_rows: int

Get the number of rows in the lattice.

Returns: int: The number of rows.

set_figsize(value)[source]

Set the figure size.

Parameters: value (tuple[float, float]): The size of the figure as (height, width).

property size_ratios: tuple[list[float], list[float]]

Get the size ratios for the rows and columns of the lattice.

Returns: tuple[list[float], list[float]]: The size ratios.

update_size_ratios(row: int, column: int)[source]

Update the size ratios based on the given row and column indices.

Parameters: row (int): The row index. column (int): The column index.

class PlotSaver(mode: str | list[str] = 'show', save_path: str | None = None, save_format: str | None = 'image_{}', animation_path: str | None = None)[source]

Bases: object

A utility class to handle the saving and display of plots.

It provides functionality to save individual plots, display them, and even create GIFs from a sequence of plots.

static is_inside_jupyter() bool[source]

Determine if the current environment is Jupyter Notebook.

Returns:

True if inside Jupyter Notebook, False otherwise.

Return type:

bool

save(fig: Figure) None[source]

Save and/or display the provided figure based on the specified mode.

Parameters:

fig (matplotlib.figure.Figure) – The figure to be saved or displayed.

add_plot(plot_type: str, plot_arguments: dict[str, str | list[str] | dict[str, Any]], row: int = 0, col: int = 0)[source]

Example

plotter.add_plot(

“Scatter”, {

“parameters”: [“Opinion”, “Activity”], “scale”: [“Linear”, “Linear”], “color”: {

“mode”: “Parameter Colormap”, “settings”: {

“parameter”: “Opinion density”, “scale”: (“Linear”, )

},

},

}, row=2, col=0,

)

add_plot_for_interface(interface: Interface, plot_type: str, plot_arguments: dict[str, str | list[str] | dict[str, Any]], row: int = 0, col: int = 0)[source]
property available_plot_types: list

Retrieves the list of available parameters/methods from the interface.

Returns:

A list of available parameters or methods.

Return type:

list

property available_plot_types_hint: str

Retrieves the list of available parameters/methods from the interface.

Returns:

A list of available parameters or methods.

Return type:

str

clear_plot(row: int, col: int)[source]

Clears axis on a given position in a grid

classmethod create_plotter(data) Plotter[source]

Class method to create a Plotter instance given data.

Parameters:

dataAny

Data used to create the Interface instance.

Returns:

Plotter

Initialized Plotter object.

property existing_plot_types: list

Retrieves the list of available parameters/methods from the interface.

Returns:

A list of available parameters or methods.

Return type:

list

classmethod get_plot_class(plot_type: str) type[Plot][source]

Converts name of the class to the class

classmethod get_plot_name(plot_class: type[Plot]) str[source]

Converts the class to its name

info() str[source]

String with the information about the plotter setup

property is_initialized: bool
property node_parameters: list

Retrieves the list of available parameters/methods from the interface.

Returns:

A list of available parameters or methods.

Return type:

list

number_of_groups() int[source]
property number_of_interfaces: int
plot(group_number: int) tuple[Figure, Axes][source]
plot_dynamics(mode: str | list[str] = 'show', save_dir: str | None = None, animation_path: str | None = None, name: str = 'opinion_histogram', preview: bool = False) None[source]

Create and display the plots based on the stored configurations. mode : [“show”, “save”, “gif”, “mp4”]

classmethod plot_type(plot_name)[source]

Decorator to register a plot method.

Parameters: plot_name (str): Name of the plot type. instructions (dict): Provides the information about the plot type and function that is used for creating the plot.

regroup(num_intervals: int, interval_size: int = 1, offset: int = 0)[source]
to_code() str[source]

Generates a string that can be used to create the current plotter setup. Can be used in GUI as well.

update_interface(new_interface)[source]