Visualizer¶
-
class
foronoi.visualization.visualizer.
Visualizer
(voronoi, canvas_offset=1, figsize=(8, 8))¶ A visualizer for your voronoi diagram.
Examples
Quickly plot individual components of the graph.
>>> vis = Visualizer(voronoi, canvas_offset=1) >>> vis.plot_sites(show_labels=True) >>> vis.plot_edges(show_labels=False) >>> vis.plot_vertices() >>> vis.plot_border_to_site() >>> vis.show()
Chaining commands
>>> Visualizer(voronoi, 1).plot_sites().plot_edges().plot_vertices().show()
Plot all components that are useful to visualize during construction of the diagram
>>> from foronoi.visualization import Presets >>> Visualizer(voronoi, 1).plot_all(**Presets.construction)
Plot all components that are useful to visualize when the diagram is constructed
>>> Visualizer(voronoi, 1).plot_all()
- Parameters
voronoi (Voronoi) – The voronoi object
canvas_offset (float) – The space around the bounding object
figsize (float, float) – Width, height in inches
-
get_canvas
()¶ Retrieve the figure.
- Returns
Figure
- Return type
matplotlib.figure.Figure
-
plot_all
(polygon=False, edges=True, vertices=True, sites=True, outgoing_edges=False, border_to_site=False, scale=1, edge_labels=False, site_labels=False, triangles=False, arcs=False, sweep_line=False, events=False, arc_labels=False, beach_line=False)¶ Convenience method that calls other methods to display parts of the diagram.
- Parameters
polygon (bool) – Display the polygon outline. Only useful during construction.
edges (bool) – Display the borders of the cells.
vertices (bool) – Display the intersections of the edges.
sites (bool) – Display the cell points (a.k.a. sites)
outgoing_edges (bool) – Show arrows of length scale in the direction of the outgoing edges for each vertex.
border_to_site (bool) – Indicate with dashed line to which site a border belongs. The site’s first edge is colored green.
scale (float) – Used to set the length of the outgoing_edges.
edge_labels (bool) – Display edge labels of format “A/B”, where the edge is A’s border and the edge’s twin is B’s border.
site_labels (bool) – Display the labels of the cell points, of format “P#”, where # is the `n`th point from top to bottom.
triangles (bool) – Display the triangle of the 3 points responsible for causing a circle event. Only useful during construction.
arcs (bool) – Display each arc for each point. Only used if beach_line is also True. Only useful during construction.
sweep_line (bool) – Display the sweep line. Only useful during construction.
events (bool) – Display circles for circle events. Only useful during construction.
arc_labels (bool) – Display labels on the arcs. Only useful during construction.
beach_line (bool) – Display the beach line. Only useful during construction.
- Returns
self
- Return type
-
plot_arcs
(arcs=None, sweep_line=None, plot_arcs=False, show_labels=True)¶ Display each arc for each point. Only used if beach_line is also True. Only useful during construction.
- Parameters
arcs (list(Arc)) –
sweep_line (Decimal) – The y-coordinate of the sweep line, used to calculate the positions of the arcs. By default, the voronoi’s sweep_line will be used.
plot_arcs (bool) – Display each arc for each point
show_labels (bool) – Display labels on the arcs.
- Returns
self
- Return type
-
plot_border_to_site
(edges=None, sweep_line=None)¶ Indicate with dashed line to which site a border belongs. The site’s first edge is colored green.
- Parameters
edges (list(
foronoi.graph.HalfEdge
), optional) – The edges to display. By default, the voronoi’s edges will be used.sweep_line (Decimal) – The y-coordinate of the sweep line, used to calculate the positions of unfinished edges. By default, the voronoi’s sweep_line will be used.
- Returns
self
- Return type
-
plot_edges
(edges=None, sweep_line=None, show_labels=True, color='#636e72', **kwargs)¶ Display the borders of the cells.
- Parameters
edges (list(
foronoi.graph.HalfEdge
), optional) – The edges to display. By default, the voronoi’s edges will be used.sweep_line (Decimal) – The y-coordinate of the sweep line, used to calculate the positions of unfinished edges. By default, the voronoi’s sweep_line will be used.
show_labels (bool) – Display edge labels of format “A/B”, where the edge is A’s border and the edge’s twin is B’s border.
color (str) – Color of the sites in hex format (e.g. “#636e72”).
- Returns
self
- Return type
-
plot_event
(event=None, triangles=False)¶ Display circles for circle events. Only useful during construction.
- Parameters
event (Event) – A circle event. Other events will be ignored.
triangles (bool) – Display the triangle of the 3 points responsible for causing a circle event.
- Returns
self
- Return type
-
plot_outgoing_edges
(vertices=None, scale=0.5, **kwargs)¶ Show arrows of length scale in the direction of the outgoing edges for each vertex.
- Parameters
vertices (list(
foronoi.graph.Vertex
), optional) – The vertices for which to display the outgoing edges. By default, the voronoi’s vertices will be used.scale (float) – Used to set the length of the outgoing_edges.
kwargs – Optional arguments that are passed to arrowprops
- Returns
self
- Return type
-
plot_polygon
()¶ Display the polygon outline. Only useful during construction.
- Returns
self
- Return type
-
plot_sites
(points=None, show_labels=True, color='#bdc3c7', zorder=10)¶ Display the cell points (a.k.a. sites).
- Parameters
points (list(
foronoi.graph.Point
), optional) – The vertices to display. By default, the voronoi’s vertices will be used.show_labels (bool) – Display the labels of the cell points, of format “P#”, where # is the `n`th point from top to bottom.
color (str) – Color of the sites in hex format (e.g. “#bdc3c7”).
zorder (int) – Higher order will be shown on top of a lower layer.
- Returns
self
- Return type
-
plot_sweep_line
(sweep_line=None)¶ Plot the sweep line.
- Parameters
sweep_line (Decimal) – The y-coordinate of the sweep line. By default, the voronoi’s sweep_line will be used.
- Returns
self
- Return type
-
plot_vertices
(vertices=None, **kwargs)¶ Display the intersections of the edges.
- Parameters
vertices (list(
foronoi.graph.Vertex
), optional) – The vertices to display. By default, the voronoi’s vertices will be used.- Returns
self
- Return type
-
show
(block=True, **kwargs)¶ Display all open figures.
- Parameters
block (bool, optional) –
If True block and run the GUI main loop until all windows are closed.
If False ensure that all windows are displayed and return immediately. In this case, you are responsible for ensuring that the event loop is running to have responsive figures.
- Returns
self
- Return type