python-igraph API reference

List of all classes, functions and methods in python-igraph

module documentation

Auxiliary classes for the default graph drawer in igraph.

This module contains heavy metaclass magic. If you don't understand the logic behind these classes, probably you don't need them either.

igraph's default graph drawer uses various data sources to determine the visual appearance of vertices and edges. These data sources are the following (in order of precedence):

  • The keyword arguments passed to the igraph.plot() function (or to igraph.Graph.__plot__() as a matter of fact, since igraph.plot() just passes these attributes on). For instance, a keyword argument named vertex_label can be used to set the labels of vertices.
  • The attributes of the vertices/edges being drawn. For instance, a vertex that has a label attribute will use that label when drawn by the default graph drawer.
  • The global configuration of igraph. For instance, if the global igraph.config.Configuration instance has a key called plotting.vertex_color, that will be used as a default color for the vertices.
  • If all else fails, there is a built-in default; for instance, the default vertex color is "red". This is hard-wired in the source code.

The logic above can be useful in other graph drawers as well, not only in the default one, therefore it is refactored into the classes found in this module. Different graph drawers may inspect different vertex or edge attributes, hence the classes that collect the attributes from the various data sources are generated in run-time using a metaclass called AttributeCollectorMeta. You don't have to use AttributeCollectorMeta directly, just implement a subclass of AttributeCollectorBase and it will ensure that the appropriate metaclass is used. With AttributeCollectorBase, you can use a simple declarative syntax to specify which attributes you are interested in. For example:

    class VisualEdgeBuilder(AttributeCollectorBase):
        arrow_size = 1.0
        arrow_width = 1.0
        color = ("black", palette.get)
        width = 1.0

    for edge in VisualEdgeBuilder(graph.es):
        print edge.color

The above class is a visual edge builder -- a class that gives the visual attributes of the edges of a graph that is specified at construction time. It specifies that the attributes we are interested in are arrow_size, arrow_width, color and width; the default values are also given. For color, we also specify that a method called {palette.get} should be called on every attribute value to translate color names to RGB values. For the other three attributes, float will implicitly be called on all attribute values, this is inferred from the type of the default value itself.

See AlsoAttributeCollectorMeta, AttributeCollectorBase
Class AttributeSpecification Class that describes how the value of a given attribute should be retrieved.
Class AttributeCollectorMeta Metaclass for attribute collector classes
Class AttributeCollectorBase No summary
API Documentation for igraph, generated by pydoctor 21.2.2.