finesse.plotting.graph module
Graph plotting.
- finesse.plotting.graph.graphviz_draw(model=None, network=None, draw_labels=True, angle=0, overlap=True, ratio=0.45, edge_len=1.0, size=(13, 7), pad=(0.0, 0.0), format: Literal['png', 'svg'] = 'svg', maxiter=500, layout='neato', mode=None, path=None, show=True)[source]
This should get merged with plot_graphviz at some point.
Draws a
graphvizfigure usingneatolayout. The default settings are tested to produce a passable drawing of the aLIGO DRMI graph.Parameters
- anglefloat or bool
The angle parameter rotates the graph by
angledegrees relative to the first edge in the graph, which most of the time is the edge coming out of the laser. Setangle=Falseto disable rotation and let graphviz decide how to rotate the graph.- overlapbool or str
Setting for how graphviz deals with node overlaps. Set to False for graphviz to attempt to remove overlaps. Note that overlap removal runs as a post-processing step after initial layout and usually makes the graph look worse.
- ratiofloat
Post processing step to stretch the graph. Used for stretching horizontally to compoensate for wider nodes to fit node labels.
- pathPath or None
Save the resulting image to the given path. Defaults to None, which saves in a temporary file that is displayed if ‘show’ is set to True.
- showbool, optional
Whether to show the resulting image. In Jupyter environments, shows the plot inline, otherwise opens a webbrowser for svgs and PIL for pngs. Defaults to True.
Notes
The svg format sometimes crops the image too hard, which results in clipped nodes or edges, if that happens increase the
padgraph_attr or use thepngformat.
- finesse.plotting.graph.graphviz_draw_beam_trace(model=None, network=None, draw_labels=True, angle=0, overlap=True, ratio=0.45, edge_len=1.0, size=(13, 7), pad=(0.5, 0.5), format: Literal['png', 'svg']='svg', maxiter=500, layout='neato', mode=None, cmap=<matplotlib.colors.ListedColormap object>)[source]
- finesse.plotting.graph.plot_dcfields_graph(model: Model, path: Path | str | None = None, show: bool = True, add_fields: bool = True, add_operators: bool = False, operator_labels: bool = False) Path[source]
Visualize the values of the DC fields in a model in a graph representation. Will run a
DCFields/finesse.analysis.actions.dc.DCFieldsaction under the hood.Parameters
- modelfinesse.Model
Model to visualize
- pathPath | str | None, optional
Save the resulting image to the given path. Defaults to None, which saves in a temporary file that is displayed if ‘show’ is set to True.
- showbool, optional
Whether to show the resulting image. In Jupyter environments, shows the plot inline, otherwise opens a webbrowser. Defaults to True.
- add_fieldsbool, optional
Whether to show the DC fields values in the nodes of the graph, by default True
- add_operatorsbool, optional
Whether to show the couplings between nodes as edge tooltips, by default False. Only supported for plane-wave single frequency models for now.
- add_operatorsbool, optional
Show operator values directly as edge labels. Can clutter the view. By default False
Returns
- pathlib.Path
Path where the svg was saved
Raises
- ModuleNotFoundError
If pygraphviz is not installed
- NotImplementedError
When
add_operatorsis True, but the model is not plane-wave single frequency
- finesse.plotting.graph.plot_graph(network, layout, graphviz=True, path=None, show=True, format: Literal['png', 'svg'] = 'svg', **kwargs)[source]
- finesse.plotting.graph.plot_graphviz(network, layout)[source]
Plot graph with graphviz.
The pygraphviz Python package must be installed and available on the current Python path, and graphviz must be available on the system path.
Parameters
- network
networkx.Graph The network to plot.
- layoutstr
The layout type to use. Any layout algorithm provided by graphviz is supported.
Raises
- ValueError
If the specified layout is not supported.
- ImportError
If graphviz or pygraphviz is not installed.
- network
- finesse.plotting.graph.plot_nx_graph(network, layout, node_labels=True, node_attrs=False, edge_attrs=False, node_color_key=None, edge_color_key=None, label_font_size=12, attr_font_size=6, edge_font_size=6, bounding_ellipses=True, format: Literal['png', 'svg'] = 'svg', path: Path | None = None, show=True, **kwargs)[source]
Plot graph with NetworkX.
Parameters
- network
networkx.Graph The network to plot.
- layoutstr
The layout type to use. Any layout algorithm provided by
networkx.drawing.layoutis supported.- node_labels
bool, optional Show node names; defaults to True.
- node_attrs
boolorlist, optional Show node data. This can be True, in which case all node data is shown, or a list, in which case only the specified keys are shown. Defaults to True.
- edge_attrs
boolorlist, optional Show edge data. This can be True, in which case all edge data is shown, or a list, in which case only the specified keys are shown. Defaults to True.
- node_color_keycallable, optional
Key function accepting a node and its attribute
dictand returning a group. Each group is assigned a unique color. If not specified, nodes are not colored.- edge_color_keycallable, optional
Key function accepting an edge (u, v) and its attribute
dictand returning a group. Each group is assigned a unique color. If not specified, edges are not colored.- label_font_size, attr_font_size, edge_font_size
int, optional Font size for node labels, attributes and edges. Defaults to 12, 6 and 6, respectively.
- bounding_ellipses: bool, optional
Hijack the node label bounding boxes to draw the node labels inside of an ellipse (similar to graphviz neato layout). This guarantees the label is readable, but the arrow direction might not always be clear and might not combine well with node_color_key. Defaults to True.
- pathPath or None
Save the resulting image to the given path. Defaults to None, which saves in a temporary file that is displayed if ‘show’ is set to True.
- showbool, optional
Whether to show the resulting image. In Jupyter environments, shows the plot inline, otherwise opens a webbrowser for svgs and PIL for pngs. Defaults to True.
Other Parameters
- kwargs
Anything else supported by
networkx.drawing.nx_pylab.draw().
Raises
- ValueError
If the specified layout is not supported.
- Exception
If the graph cannot be represented with the specified layout.
- network
- finesse.plotting.graph.show_graphviz(A: pygraphviz.AGraph, format: str, path: str | Path | None, layout: str, show: bool) pathlib.Path[source]