
Displays a network graph diagram of the agents for a particular registered network. This plot requires NetworkX to be installed.
This class should not be instantiated directly; use Charts.addPlot(type='network')
instead. The optional init options can be passed to that function as kwargs.
Features
- Nodes are displayed with their breed color and agent ID.
- Edges are displayed with both weight and direction.
- The network layout can be set when registering the plot, or cycle through various layouts by pressing ‘l’.
- Nodes are clickable; clicked agents are passed to a
networkNodeClick
hook.
Initialization Parameters
prim — str, optional
Whether to limit the agent display to a particular agent primitive.
Default value: None
kind — str, optional
The name of the network to display. Corresponds to the
kind
argument ofAgent.addEdge()
.Default value: 'edge'
layout — str, optional
The Networkx layout class to use. Possible values are
'spring'
,'circular'
,'kamada_kawai'
,'random'
,'shell'
,'spectral'
, and'spiral'
. See the NetworkX documentation for details on each of these.Default value: 'spring'
Methods
Click a method name for more detailed documentation.
draw( t, forceUpdate )
Updates the
axes
object for display on the visualizer. This function is called afterChartPlot.update()
when the visualizer receives new data, and when scrubbing the time bar. Theupdate()
method, therefore, should be used to store model data by time, which can then be used bydraw()
.Charts will refresh the entire canvas after updating each of the individual plots, so there is no need to refresh the canvas manually here unless it is desired to redraw the graph out of sync (e.g. if the subclass provides for interactivity and the plot should update while the model is paused).
Subclasses should call
super().draw(t, forceUpdate)
at the end of the function.rotateLayout( )
Rotates the layout of the Network plot among the several NetworkX layout classes (
'spring'
,'circular'
,'kamada_kawai'
,'random'
,'shell'
,'spectral'
, and'spiral'
). This function is called when pressing 'l' with the mouse over the plot. See the NetworkX documentation for details on each of these.update( data, t )
Receives current model data and stores it for future scrubbing.
Note that this function is called when the visualizer receives new data from the model. Because
ChartPlot.draw()
is called both afterChartPlot.update()
and when the time bar is scrubbed, drawing code should be but inChartPlot.draw()
and not here, unless there is code to be run only in the event of new data that should not be run when scrubbing (e.g. calculating new plot bounds).If the visualizer needs model properties besides the current data, the model object can be accessed with
self.viz.model
.This function should not typically be called from user code, though it can be for out-of-sync plot updates when interacting with a plot. See the
networkNodeClick
hook for an example.launch( axes )
Initial code to set up
ChartPlot.axes
whenCharts
launches the visualization window. Subclasses should callsuper().launch()
at the beginning of the method. This function should not be called from user code.
Properties
type — str
A short identifying string, to be used in the
type
argument ofCharts.addPlot()
.name — str
A short name, used to refer back to the plot afterward.
label — str
The title of the chart, displayed above it in the visualizer.
axes — matplotlib.AxesSubplot
The
AxesSubplot
object to be drawn to the plot area. The object is created onCharts.launch()
and passed toChartPlot.launch()
, where it must be stored subsequently.projection — str
The Matplotlib coordinate projection to use.
None
defaults to'rectilinear'
, but other projections available by default are'polar'
,'3d'
,'aitoff'
,'hammer'
,'lambert'
, and'mollweide'
. Custom Matplotlib projection objects can also be passed to this argument.Initial value: None
viz — Charts
The parent
Charts
visualizer object.selected — bool
Whether or not the plot should be drawn when
Charts
is launched.prim — str
Whether the agent display is limited to a particular agent primitive.
Initial value:
kind — str
The name of the network being displayed. Corresponds to the
kind
argument ofAgent.addEdge()
.Initial value:
layout — str
The current Networkx layout class being used. Possible values are
'spring'
,'circular'
,'kamada_kawai'
,'random'
,'shell'
,'spectral'
, and'spiral'
. See the NetworkX documentation for details on each of these.
Hooks
Click a hook name for more detailed documentation.
networkNodeClick( agents, plot, t )
Runs when a node is clicked in the NetworkPlots axes.
Notes and Examples