deflex.DeflexGraph.color_edges_by_weight

DeflexGraph.color_edges_by_weight(cmap='cool', max_weight=None)[source]

Color all edges by their weight using a matplotlib color map (cmap). If no maximum weight is give the highest weight is used.

Parameters:
  • cmap (str) – Name of the matplotlib color map.
  • max_weight (numeric) – The maximum for the normalisation of the weights. All number above the max_weight will get the color of the maximum. If no value is given the maximum weight of all edges will used.

Examples

>>> from deflex import fetch_test_files
>>> from deflex import restore_results
>>> from deflex import DeflexGraph
>>> from matplotlib.cm import get_cmap
>>>
>>> fn = fetch_test_files("de03_fictive.dflx")
>>> my_results = restore_results(fn)
>>> dflx_graph = DeflexGraph(my_results)
>>> dflx_graph.color_edges_by_weight(cmap="rainbow", max_weight=80)
>>> edges = dflx_graph.edges
>>> bus = [edg for edg in edges if "wind" in edg.nodes[0].label][0]
>>> getattr(bus, "color")
'#ff0000'
>>> w = bus.weight
>>> int(w)
336973
>>> rgb2hex(get_cmap("rainbow")(w))
'#ff0000'