Plot Style

This module provides classes for defining style of plots.

class pyrigi.plot_style.PlotStyle(vertex_size=300, vertex_color='#ff8c00', vertex_labels=True, vertex_shape='o', edge_width=2.5, edge_color='black', edge_style='solid', flex_width=1.5, flex_length=0.15, flex_color='limegreen', flex_style='solid', flex_arrow_size=20, stress_color='orangered', stress_fontsize=10, stress_rotate_labels=True, stress_normalization=False, font_size=12, font_color='whitesmoke', canvas_width=6.4, canvas_height=4.8, dpi=175)[source]

Bases: object

Class for defining the plot style.

For options specific to 2D or 3D plots, see PlotStyle2D and PlotStyle3D. For specifying different colors for each edge etc., see Framework.plot2D() and Framework.plot3D().

Note that the parameters can be used directly in plot methods like Graph.plot() or Framework.plot2D().

Parameters:
  • vertex_size (float | int) – The size of the vertices.

  • vertex_color (str) – The color of the vertices given by name like "green" or hex "#00ff00".

  • vertex_labels (bool) – If True (default), vertex labels are displayed.

  • vertex_shape (str) – The shape of the vertices specified as matplotlib.pyplot.scatter() marker, one of so^>v<dph8.

  • edge_width (float | int)

  • edge_color (str) – The color of all edges given as a string (name like "green" or hex "#00ff00"). For specifying a different color for each edge, see parameter edge_colors_custom in Framework.plot2D().

  • edge_style (str) – Edge line style: -/solid, --/dashed, -./dashdot or :/dotted.

  • flex_width (float | int) – The width of the infinitesimal flex’s arrow tail.

  • flex_color (str) – The color of the infinitesimal flex.

  • flex_style (str) – Line Style: -/solid, --/dashed, -./dashdot or :/dotted.

  • flex_length (float | int) – Length of the displayed flex relative to the total canvas diagonal in percent.

  • flex_arrow_size (int) – The size of the arrowhead’s length and width.

  • stress_color (str) – The color of the font used to label the edges with stresses.

  • stress_fontsize (int) – Fontsize of the stress labels.

  • stress_rotate_labels (bool) – A boolean indicating whether the stress label should be rotated.

  • stress_normalization (bool) – A boolean indicating whether the stress values should be turned into floating point numbers. If True, the stress is automatically normalized.

  • font_size (int) – The size of the font used for the labels.

  • font_color (str) – The color of the font used for the labels.

  • canvas_width (float | int) – The width of the canvas in inches.

  • canvas_height (float | int) – The height of the canvas in inches.

  • dpi (int) – DPI (dots per inch) for the plot.

Examples

>>> from pyrigi import Graph
>>> G = Graph([(0,1), (1,2), (2,3), (0,3)])
>>> plot_style = PlotStyle(vertex_color="#FF0000", edge_color="black", vertex_size=50)
>>> G.plot(plot_style)

To change the plot style later, use the update() method:

>>> plot_style.update(vertex_color="#00FF00")
>>> G.plot(plot_style)

Or assign to the attributes:

>>> plot_style.vertex_color = "blue"
>>> G.plot(plot_style)
update(**kwargs)[source]

Update the plot style attributes from the keyword arguments.

class pyrigi.plot_style.PlotStyle2D(aspect_ratio=1.0, edges_as_arcs=False, arc_angle=0.5235987755982988, **kwargs)[source]

Bases: PlotStyle

Class for defining the 2D plot style.

Parameters:
  • aspect_ratio (float | int) – The ratio of y-unit to x-unit.

  • edges_as_arcs (bool) – If True (default), the edges are displayed as arcs.

  • arc_angle (float | int) – Only if edges_as_arcs=True: the pitch of the edge arcs in radians. For setting different values for individual edges, see arc_angles_dict in Framework.plot2D().

Examples

>>> from pyrigi import Framework, PlotStyle2D
>>> F = Framework.Complete([(0,1), (1,2), (0,2)])
>>> plot_style_2d = PlotStyle2D(aspect_ratio=1, edges_as_arcs=True, arc_angle=np.pi/6)
>>> F.plot2D(plot_style_2d)

To update the plot style, you can assign to the attributes:

>>> plot_style_2d.aspect_ratio = 0.75
>>> plot_style_2d.edges_as_arcs = False
>>> F.plot2D(plot_style_2d)

Or use the update() method:

>>> plot_style_2d.update(aspect_ratio=1.0, edges_as_arcs=True, arc_angle=np.pi/4)
>>> F.plot2D(plot_style_2d)
classmethod from_plot_style(plot_style)[source]

Construct an instance from a given instance of PlotStyle.

Parameters:

plot_style (PlotStyle) – A PlotStyle instance to copy attributes from.

Return type:

PlotStyle

class pyrigi.plot_style.PlotStyle3D(padding=0.01, axis_scales=(1.0, 1.0, 1.0), **kwargs)[source]

Bases: PlotStyle

Class for defining the 3D plot style.

Parameters:
  • axis_scales (Sequence[float | int]) – A triple indicating the scaling of the three axes.

  • padding (float | int) – Padding value for the plot.

Examples

>>> from pyrigi import Framework, PlotStyle3D
>>> F = Framework.Complete([(0,1,2), (1,2,3), (2,3,0), (0,3,1)])
>>> plot_style_3d = PlotStyle3D(padding=0.05, axis_scales=(2.0, 2.0, 2.0))
>>> F.plot(plot_style_3d)

To update the plot style, you can assign to the attributes:

>>> plot_style_3d.padding = 0.10
>>> plot_style_3d.axis_scales = (1.0, 2, 1.0)
>>> F.plot(plot_style_3d)

Or use the update() method:

>>> plot_style_3d.update(padding=0.15, axis_scales=(1.0, 1.0, 3))
classmethod from_plot_style(plot_style)[source]

Construct an instance from a given instance of PlotStyle.

Parameters:

plot_style (PlotStyle) – A PlotStyle instance to copy attributes from.

Return type:

PlotStyle