Plot

Module for plotting functionality.

pyrigi.framework._plot.plot.animate3D_rotation(framework, plot_style=None, vertex_colors_custom=None, edge_colors_custom=None, total_frames=100, delay=75, rotation_axis=None, **kwargs)[source]

Plot this framework in 3D and animate a rotation around an axis.

For additional parameters and implementation details, see animate3D().

Parameters:
  • framework (FrameworkBase)

  • plot_style (PlotStyle) – An instance of the PlotStyle class that defines the visual style for plotting, see PlotStyle for more details.

  • vertex_colors_custom (Sequence[Sequence[Vertex]] | dict[str, Sequence[Vertex]]) – Optional parameter to specify the colors of vertices. It can be a Sequence[Sequence[Vertex]] to define groups of vertices with the same color or a dict[str, Sequence[Vertex]] where the keys are color strings and the values are lists of vertices. The omitted vertices are given the value plot_style.vertex_color.

  • edge_colors_custom (Sequence[Sequence[Edge]] | dict[str, Sequence[Edge]]) – Optional parameter to specify the colors of edges. It can be a Sequence[Sequence[Edge]] to define groups of edges with the same color or a dict[str, Sequence[Edge]] where the keys are color strings and the values are lists of edges. The omitted edges are given the value plot_style.edge_color.

  • total_frames (int) – Total number of frames for the animation sequence.

  • delay (int) – Delay between frames in milliseconds.

  • rotation_axis (str | Sequence[Number]) – The user can input a rotation axis or vector. By default, a rotation around the z-axis is performed. This can either a character ('x', 'y', or 'z') or a vector (e.g. [1, 0, 0]).

Return type:

Any

Examples

>>> from pyrigi import frameworkDB
>>> F = frameworkDB.Complete(4, dim=3)
>>> animate3D_rotation(F)
pyrigi.framework._plot.plot.plot(framework, plot_style=None, **kwargs)[source]

Plot the framework.

The framework can be plotted only if its dimension is less than 3. For plotting a projection of a higher dimensional framework, use plot2D() or plot3D() instead. For various formatting options, see PlotStyle.

Return type:

None

Parameters:
pyrigi.framework._plot.plot.plot2D(framework, plot_style=None, projection_matrix=None, random_seed=None, coordinates=None, inf_flex=None, stress=None, vertex_colors_custom=None, edge_colors_custom=None, stress_label_positions=None, arc_angles_dict=None, filename=None, dpi=300, fixed_vertices=[], **kwargs)[source]

Plot the framework in 2D.

If the framework is in dimensions higher than 2 and projection_matrix with coordinates are None, a random projection matrix containing two orthonormal vectors is generated and used for projection into 2D. For various formatting options, see PlotStyle. Only coordinates or projection_matrix parameter can be used, not both!

Parameters:
  • framework (FrameworkBase)

  • plot_style (PlotStyle) – An instance of the PlotStyle class that defines the visual style for plotting, see PlotStyle for more details.

  • projection_matrix (MutableDenseMatrix) – The matrix used for projecting the realization when the dimension is greater than 2. The matrix must have dimensions (2, dim), where dim is the dimension of the framework. If None, a random projection matrix is generated.

  • random_seed (int) – The random seed used for generating the projection matrix.

  • coordinates (Sequence[int]) – Indices of two coordinates to which the framework is projected.

  • inf_flex (Union[int, InfFlex]) – Optional parameter for plotting a given infinitesimal flex. The standard input format is a Matrix that is the output of e.g. the function inf_flexes(). Alternatively, an int can be specified to directly choose the 0,1,2,…-th nontrivial infinitesimal flex (according to the function nontrivial_inf_flexes()) for plotting. For these input types, it is important to use the same vertex order as the one from Graph.vertex_list(). If the vertex order needs to be specified, a dict[Vertex, Sequence[Number]] can be provided, which maps the vertex labels to vectors (i.e. a sequence of coordinates).

  • stress (Union[int, Stress]) – Optional parameter for plotting a given equilibrium stress. The standard input format is a Matrix that is the output of e.g. the function stresses(). Alternatively, an int can be specified to directly choose the 0,1,2,…-th equilibrium stress (according to the function stresses()) for plotting. For these input types, it is important to use the same edge order as the one from Graph.edge_list(). If the edge order needs to be specified, a Dict[Edge, Number] can be provided, which maps the edges to numbers (i.e. coordinates).

  • vertex_colors_custom (Sequence[Sequence[Vertex]] | dict[str, Sequence[Vertex]]) – It is possible to provide custom vertex colors through this parameter. They can either be provided through a partition of vertices or a dictionary with str color keywords that map to lists of vertices.

  • edge_colors_custom (Sequence[Sequence[Edge]] | dict[str, Sequence[Edge]]) – Optional parameter to specify the colors of edges. It can be a Sequence[Sequence[Edge]] to define groups of edges with the same color or a dict[str, Sequence[Edge]] where the keys are color strings and the values are lists of edges. The omitted edges are given the value plot_style.edge_color.

  • stress_label_positions (dict[DirectedEdge, float]) – Dictionary specifying the position of stress labels along the edges. Keys are DirectedEdge objects, and values are floats (e.g., 0.5 for midpoint). Omitted edges are given the value 0.5.

  • arc_angles_dict (Sequence[float] | dict[DirectedEdge, float]) – Optional parameter to specify custom arc angle for edges. Can be a Sequence[float] or a dict[Edge, float] where values define the curvature angle of edges in radians.

  • filename (str) – The filename under which the produced figure is saved. The default value is None which indicates that the figure is currently not saved. The figure is saved as a .png file using the save method from matplotlib.

  • dpi (int) – Dots per inched in case the figure is saved. Default is 300 for producing a print-quality image.

  • fixed_vertices (Sequence[Vertex]) – Vertices that are assigned a zero flex in the plot.

Return type:

None

Examples

>>> from pyrigi import Graph, Framework
>>> G = Graph([(0,1), (1,2), (2,3), (0,3), (0,2), (1,3), (0,4)])
>>> F = Framework(G, {0:(0,0), 1:(1,0), 2:(1,2), 3:(0,1), 4:(-1,0)})
>>> from pyrigi import PlotStyle2D
>>> style = PlotStyle2D(vertex_color="green", edge_color="blue")
>>> plot2D(F, plot_style=style)

Use keyword arguments

>>> plot2D(F, vertex_color="red", edge_color="black", vertex_size=500)

Specify stress and its labels positions

>>> stress_label_positions = {(0, 1): 0.7, (1, 2): 0.2}
>>> plot2D(F, stress=0, stress_label_positions=stress_label_positions)

Specify infinitesimal flex

>>> plot2D(F, inf_flex=0)

Use both stress and infinitesimal flex

>>> plot2D(F, stress=0, inf_flex=0)

Use custom edge colors

>>> edge_colors = {'red': [(0, 1), (1, 2)], 'blue': [(2, 3), (0, 3)]}
>>> plot2D(F, edge_colors_custom=edge_colors)

The following is just to close all figures after running the example:

>>> import matplotlib.pyplot
>>> matplotlib.pyplot.close("all")
pyrigi.framework._plot.plot.plot3D(framework, plot_style=None, projection_matrix=None, random_seed=None, coordinates=None, inf_flex=None, stress=None, vertex_colors_custom=None, edge_colors_custom=None, stress_label_positions=None, filename=None, dpi=300, fixed_vertices=[], **kwargs)[source]

Plot the provided framework in 3D.

If the framework is in a dimension higher than 3 and projection_matrix with coordinates are None, a random projection matrix containing three orthonormal vectors is generated and used for projection into 3D. For various formatting options, see PlotStyle. Only the parameter coordinates or projection_matrix can be used, not both at the same time.

Parameters:
  • framework (FrameworkBase)

  • plot_style (PlotStyle) – An instance of the PlotStyle class that defines the visual style for plotting, see PlotStyle for more details.

  • projection_matrix (MutableDenseMatrix) – The matrix used for projecting the realization when the dimension is greater than 3. The matrix must have dimensions (3, dim), where dim is the dimension of the framework. If None, a random projection matrix is generated.

  • random_seed (int) – The random seed used for generating the projection matrix.

  • coordinates (Sequence[int]) – Indices of two coordinates to which the framework is projected.

  • inf_flex (Union[int, InfFlex]) – Optional parameter for plotting a given infinitesimal flex. The standard input format is a Matrix that is the output of e.g. the function inf_flexes(). Alternatively, an int can be specified to directly choose the 0,1,2,…-th nontrivial infinitesimal flex (according to the function nontrivial_inf_flexes()) for plotting. For these input types, is important to use the same vertex order as the one from Graph.vertex_list(). If the vertex order needs to be specified, a dict[Vertex, Sequence[Number]] can be provided, which maps the vertex labels to vectors (i.e. a sequence of coordinates).

  • stress (Union[int, Stress]) – Optional parameter for plotting a given equilibrium stress. The standard input format is a Matrix that is the output of e.g. the function stresses(). Alternatively, an int can be specified to directly choose the 0,1,2,…-th equilibrium stress (according to the function stresses()) for plotting. For these input types, is important to use the same edge order as the one from Graph.edge_list(). If the edge order needs to be specified, a Dict[Edge, Number] can be provided, which maps the edges to numbers (i.e. coordinates).

  • vertex_colors_custom (Sequence[Sequence[Vertex]] | dict[str, Sequence[Vertex]]) – Optional parameter to specify the colors of vertices. It can be a Sequence[Sequence[Vertex]] to define groups of vertices with the same color or a dict[str, Sequence[Vertex]] where the keys are color strings and the values are lists of vertices. The omitted vertices are given the value plot_style.vertex_color.

  • edge_colors_custom (Sequence[Sequence[Edge]] | dict[str, Sequence[Edge]]) – Optional parameter to specify the colors of edges. It can be a Sequence[Sequence[Edge]] to define groups of edges with the same color or a dict[str, Sequence[Edge]] where the keys are color strings and the values are lists of edges. The omitted edges are given the value plot_style.edge_color.

  • stress_label_positions (dict[DirectedEdge, float]) – Dictionary specifying the position of stress labels along the edges. Keys are DirectedEdge objects, and values are floats (e.g., 0.5 for midpoint). Omitted edges are given the value 0.5.

  • filename (str) – The filename under which the produced figure is saved. The default value is None which indicates that the figure is currently not saved. The figure is saved as a .png file using the save method from matplotlib.

  • dpi (int) – Dots per inched in case the figure is saved. Default is 300 for producing a print-quality image.

  • fixed_vertices (Sequence[Vertex]) – Vertices that are assigned a zero flex in the plot.

Return type:

None

Examples

>>> from pyrigi import frameworkDB
>>> F = frameworkDB.Octahedron(realization="Bricard_plane")
>>> plot3D(F)
>>> from pyrigi import PlotStyle3D
>>> style = PlotStyle3D(vertex_color="green", edge_color="blue")
>>> plot3D(F, plot_style=style)

Use keyword arguments

>>> plot3D(F, vertex_color="red", edge_color="black", vertex_size=500)

Specify stress and its positions

>>> stress_label_positions = {(0, 2): 0.7, (1, 2): 0.2}
>>> plot3D(F, stress=0, stress_label_positions=stress_label_positions)

Specify infinitesimal flex

>>> plot3D(F, inf_flex=0)

Use both stress and infinitesimal flex

>>> plot3D(F, stress=0, inf_flex=0)

Use custom edge colors

>>> edge_colors = {'red': [(5, 1), (1, 2)], 'blue': [(2, 4), (4, 3)]}
>>> plot3D(F, edge_colors_custom=edge_colors)

The following is just to close all figures after running the example:

>>> import matplotlib.pyplot
>>> matplotlib.pyplot.close("all")