Provide generic function for graph plotting

Description

Dantro's network group does contain a create_graph function that allows the user to create a network directly from the data container storing vertex and edge data. Further, networkx provides a network drawing function that draws the network in a matplotlib figure. Using Utopia's plotting framework, especially the possibility to provide parameters via configuration files calls for a generic network drawing function in utopya.

Proposal

Write a generic draw_network function that creates a graph using the corresponding NetworkGroup member function, and draws it. The drawing is essentially based on the functions draw_networkx_nodes, draw_networkx_edges, draw_networkx_labels and draw_networkx_edge_labels (further information on additional parameters in the reference manual or in the documentation.

Apart from wrapping those plotting functions, this function should provide additional features (controllable via the config). Possible features would be

  • Property mapping, i.e., representing properties of network entities by layout properties (e.g. some trait value is represented by the node size). The network properties could be specified in the cfg by passing a dictionary , e.g.
nodes:
  node_size:
    from_property: some_trait  # 'some_trait' is a dataset or TimeSeriesGroup in the NetworkGroup
                               # with the attribute `is_node_property`
    scale_to_interval: [0.,1.] # possible linear rescaling of the values to a given interval
  ... # more kwargs that are passed to draw_networkx_nodes
  • Select method. It might be useful to be able to plot only parts of the network. A good way to do this would be using the nodelist (and analogously edgelist) argument of the draw_networkx_nodes function. The graph object is then created using all nodes and edges and selecting only parts of it would zoom into the respective region (i.e., the positioning is the same as for the complete graph).

  • Animation support: Note that animations are only realizable for fixed node positions.

Possible future extensions:

  • directly loading data from DAG: It should be possible to also use DAG-transformed data in the graph creation. Taken care of in dantro#145 (closed).
  • mark feature: provide a list of nodes (and edges?) that are then highlighted
  • Allow creating animations not only depending on the time dimension but generalize it to use a frames keyword analogously to the new facet_grid plot function
  • show_open_edges feature: This is an extension of the select feature. It allows also showing all "open" edges, i.e., edges for which only source or destination is in the list of selected nodes.

All configurations would be passed in a graph_cfg which has the following structure:

graph_cfg:
  graph_creation: # passed to the create_graph method
    ...
  graph_drawing:
    positions: # for node positioning
      model: some_positioning_model
      # kwargs ...
    select: # node selection feature
      nodes: [0,1,2,3,4,5] # Either from list ...
      radial: True         # ... _or_ radial selection
      center: 0
      radius: 2
    nodes: # parsed and passed to draw_networkx_nodes
      ...
    edges: # parsed and passed to draw_networkx_edges
      ...
    node_labels: # parsed and passed to draw_networkx_labels
      ...
    edge_labels: # parsed and passed to draw_networkx_edge_labels
      ...
  graph_animation:
    times: # specify animation times by value or by index
      ...

How to test the implementation?

Test the plot using the CopyMeGraph model and call the plot in the pipeline.

Related issues

dantro#58 (closed), #140 (closed)

People involved

@jeremiastraub @herdeanu @blsqr

Edited by Utopia Developers