API

nx3d.demo(**kwargs)[source]

Runs a demo visualization. Good for checking that your installation worked.

nx3d.plot(g, debug=False, **kwargs)[source]

Plot my graph now!

This is where you should start. Calling this function on your graph will cause a pop-up containing the visualization to appear.

Parameters
  • g (nx.Graph) – The graph you’d like to plot.

  • debug (bool) – Set to debug mode, entailing rendered and stdout debugging information, negates other debug-like args

  • kwargs – Passed to main class initialization, see Nx3D’s docs for more info.

Returns

None

class nx3d.Nx3D(graph=<networkx.classes.graph.Graph object>, pos=None, node_color=(0.4, 0, 0.3, 1), node_size=1.0, node_labels={}, node_label_color=(0, 1, 0, 1), edge_color=(0.3, 0.3, 0.3, 0.5), edge_labels={}, edge_label_color=(0, 1, 0, 1), lights=[('directional', 'nodes', {'hpr': (180, -20, 180), 'color': 0.3}), ('directional', 'edges', {'hpr': (180, -20, 0), 'color': 0.1}), ('ambient', 'both', {'color': 0.9}), ('point', 'both', {'color': 0.5, 'pos': (0, 0, 0)})], state_trans_delay=1.0, state_trans_func=None, nofilter=False, nogui=False, nolabels=False, plot_axes=False, autolabel=False, autolabel_nodes=False, autolabel_edges=False, mouse=False, windowsize=(650, 450), windowtitle='Nx3D', **kwargs)[source]

This class provides a networkx.Graph-based API for a lightweight 3D visualization.

Usage:

` g = nx.frucht_graph(); app = Nx3D(g, autolabel=True); app.run(); `

Configuration is applied in the following order:
  1. Render attributes on the nodes and edges e.g. g.nodes[…][‘color’]

  2. Arguments to this function

The render attributes are:
  • ‘color’: panda3d.Vec4 with values in [0, 1]

  • ‘pos’: panda3d.Vec3 in x y z order

  • ‘label’: str

  • ‘label_color’: Vec4

  • ‘pos’: Vec3, note that dynamic positions aren’t supported yet, see https://github.com/ekalosak/nx3d/issues/19

for nodes there is an extra one:
  • ‘shape’: Vec3, same note as pos

Note that these render attributes will typically be overwritten in place.

For more info, see Usage.

Parameters
  • g – The graph you’d like to plot.

  • pos (Optional[dict[Hashable, LVector3f]]) – Positions of the nodes in the graph. If None, spring_layout will be used.

  • node_color (LVector4f) – Default RGBA color for the nodes.

  • node_size (float) – Default size of the nodes.

  • node_labels (dict) – Map from the graph’s nodes to string labels.

  • edge_color (LVector4f) – Default RGBA color for the edges. Currently homogeneous colors only suppported.

  • edge_labels (dict) – Map from the graph’s edges to string labels.

  • lights (list[tuple[str, str, dict]]) – Configure the lighting in your scene, see Default for example

  • state_trans_delay (float) – How often, in seconds, to apply the <state_trans_func>.

  • state_trans_func (Optional[Callable[[Graph, int, float], Any]]) – A state transfer function for <g>’s state. Set attributes on graph components to update the render. If not None, the graph’s nodes and edges must be annotated with ‘color’ and ‘label’ entries in the annotation dictionary i.e. g.nodes[nd][‘color’] must exist for all nodes.

  • nofilter – Don’t use any filters - can help your framerate for large graphs.

  • nogui – Don’t show help or diagnostic information on screen - for a cleaner look.

  • plot_axes – Show the XYZ axes in the 3D scene

  • autolabel – Use the string representation of both the nx.Graph’s nodes and edges as labels. Autolabel supercedes autolabel_nodes and autolabel_edges when True.

  • autolabel_nodes – Use the string representation of the nx.Graph’s nodes as labels.

  • autolabel_edges – Use the string representation of the nx.Graph’s edges as labels.

  • mouse – Use mouse control rather than keyboard control.

  • windowsize – Tuple of height, width of the popup window.

  • windowtitle – Title of the popup window.

  • kwargs – Passed to the base class ShowBase.

Returns

The Panda3D object capable of rendering the graph https://docs.panda3d.org/1.10/python/reference/direct.showbase.ShowBase?highlight=showbase#module-direct.showbase.ShowBase

Return type

panda3d.ShowBase

nx3d.Nx3D.flush_latest_keystroke(self)
Return type

Optional[str]

Returns

This function returns the latest keystroke (e.g. ‘r’) pressed by the user. If you call it before the user presses another key (or before they press any) you will get None.

See https://docs.panda3d.org/1.10/python/programming/hardware-support/keyboard-support#keystroke-events for more information on the keystroke monitoring event system.