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
- 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_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.
- 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.
- 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
- 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
- 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
- property number_of_interfaces: int
- 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.