The cxnet module with igraph

The functions and classes documented below are valid if you use the cxnet with igraph. If you want to use cxnet with networkx, the usage of the functions and classes or even the existence of them may differ.

Creating and getting networks


Creates the network of deb packages in Linux distributions using deb packages.

A cxnet.Network instance.

It needs the python-apt package installed.


Loads netdata from a gml file in netdata directory.

If it is not there, it will download it.

filename: string
The name of the file we want to load (without extension) or the start of the filename. It loads the first file that match.
A Network object with the archived network in it.


>>> import cxnet
I have found an rc file: /home/ha/
The graph_module was set in the rc file to "igraph".
I will use igraph. (It have been imported.)
>>> net=cxnet.load_netdata("as-")
'netdata/as-22july06.gml' have been loaded.
>>> print(net.summary())
IGRAPH U--- 22963 48436 -- as-22july06.gml
+ attr: info (g), name (g), id (v), label (v)
>>> print(net['info'])
The file as-22july06.gml contains a symmetrized snapshot of the structure
of the Internet at the level of autonomous systems, reconstructed from BGP
tables posted at  This snapshot was created by Mark
Newman from data for July 22, 2006 and is not previously published.
cxnet.get_netdata(archive_name=None, unzip=True, path='/home/ha/.cxnet')

Get network data from archives.

It stores it in the netdata subdirectory of the current directory. The downloaded zipped files are in the netdata_zip subdirectory of the current directory.

archive_name: 'newman' or 'deb'

If newman, it downloads a lot of network form Mark Newman’s site.

If deb, it downloads a lot of deb package dependency network created with cxnet.

unzip: boolean
If True, it will unzip the archive files.


>>> import cxnet
I have found an rc file: /home/ha/
The graph_module was set in the rc file to "igraph".
I will use igraph. (It have been imported.)
>>> cxnet.get_netdata('deb')
    ubuntu-10.04-packages-2010-08-19.gml, ubuntu-10.04-packages-2010-08-19.txt
    ubuntu-10.04-packages-2010-10-25.gml, ubuntu-10.04-packages-2010-10-25.txt
    ubuntu-9.10-packages-2010-07-16.gml, ubuntu-9.10-packages-2010-07-16.txt
    ubuntu-9.10-packages-2010-07-22.gml, ubuntu-9.10-packages-2010-07-22.txt
    debian-6.0-packages-2011-02-03.gml, debian-6.0-packages-2011-02-03.txt

The Network class

The Network class is derived from the igraph.Graph class. The Graph class is imported in the cxnet class for convenience, so it is available as:

class cxnet.Graph

The methods of the Graph module is described in the igraph homepage.

class cxnet.Network(*args, **kwds)

Complex Network, Igraph version

Derived from the igraph.Graph class. Methods defined here start with “cx” to find them easier.

It includes the plot function as well.

plot(target=None, labels=True, **kwargs)

It is almost same az igraph.plot().

But it has not a graph argument, and left and right margins are wider by default, and edges are orange if there are vertex labels.

target: string or None
As in igraph.plot.
labels: list or boolean
If it is a list, it will passed to the vs[“label”]. If it is true, and no “label” attribute, but there is “name” attribute, the “name” will passed to “label”.
cxlargest_degrees(direction=None, limit=None, print_it=False)

Returns with the vertices with the largest degrees.

direction: default None
Can be ‘in’, ‘out’, or None, it will be use indegree, outdegree or (plain) degree respectively.
limit: integer or None, default None

Only the packages with the degree < limit will listed.

If None, a limit will be set (good for debian package dependency network):

  • plain: 500
  • in: 300
  • out: 50
hd: a list of pairs of (degree, package name)


cn.cxlargest_degree(direction='in', limit=500)

Returns with the successors and predecessors (“out and inneighbors”) if it is a directed networks. Neighbors otherwise.

pkg_name: string
The name of the package. (You can find it with the cxfind method.)
In a directed network

returns a tuple of (predecessors, successors) where

  • predecessors are list of neighbors on incoming edges,
  • successors are list of neighbors on outcoming edges.
In an undirected network
returns a tuple of (neighbors, None) where neighbors are list of neighbors.
cxneighborhood(pkg_name, plot=True, **kwargs)

Returns with the successors and predecessors and the package itself and can plot them.

pkg_name: string or integer
The name of the package or the index of the vertex.
plot: boolean or string, default False
  • If it is one of “pdf”, “png”, “svg” or “ps”, the output will be a file like neighbors_of_pkg_name.pdf. With igraph 0.6.1+ you can use “eps” as well.
  • If other string, the output will be a file named in the string.
  • If True, plot to the screen.
  • If False, do not plot.
return_network: boolean
If True, returns with a cxnet.Network instance instead of VertexSequence
Vertex sequence of the neighborhood.


>>> import cxnet
>>> cxnet.load_netdata('ubuntu-10.10')
'netdata/ubuntu-10.10-packages-2011-05-01.gml' have been loaded.
>>> net.cxfind('vim')
['jvim-canna', 'libtext-vimcolor-perl', 'vim', 'vim-addon-manager', 'vim-common', 'vim-dbg', 'vim-gnome', 'vim-gtk', 'vim-gui-common', 'vim-latexsuite', 'vim-nox', 'vim-rails', 'vim-runtime', 'vim-tiny', 'vim-vimoutliner']
>>> net.cxneighborhood("vim")
<igraph.VertexSeq object at ...>
>>> net.cxneighborhood("vim", plot=False)
<igraph.VertexSeq object at ...>

Returns with a DegreDistribution class analyzing and plotting distribution.

parameters to the DegreeDistribution class Eg. direction {“in”, “out”, None}
dd: DegreeDistribution class object (see help(dd) )
cxfind(namepart, verbosity=None)

Returns the ordered list of package names containing the given part.

namepart: string
A part of the package name. At least 2 characters.
names: ordered list of strings
The ordered list of package names containing namepart.

The DegreeDistribution class

class cxnet.DegreeDistribution(network_or_degree_list, verbose=True, **kwargs)

Make, analyze and plot the degree distribution.

the investigated network (NetworkX or IGraph) or the list of degrees or the dict of the form {vertex:degree}.
direction: “in”, “out”, None [default]
the direction of the connection to count. If None, plain degree will be used.

some variables:

  • dd: the degree distribution az a pair of (k, p_k) values
  • dd_smeared: as the dd, but with bin smearing
  • max_deg: maximum of degree
  • number_of_vertices: the number of vertices in the network
  • n_0: the number of vertices with zero degree

more important functions:

  • summary: Write informations to screen or file about the distribution.
  • plot, loglog, semilogy, errorbar: Plotting functions as in pylab.
  • bin_smearing: Return the bin smeared distribution.
  • set_binning: Set the type of the binning.
  • cumulative_plot: Plots the cumulative distribution.

Return the cumulative degree distribution

The distribution is a list of (k, P(>k)) pairs.

cumulative_plot(with_powerlaw=False, **kwargs)

Plot the cumulative distribution.

with_powerlaw: boolean
Whether to plot the calculated powerlaw as well or not.

Return with exponent and sigma of exponent.

k_min: float or integer, k_min>0
the minimal degree in the equation referenced below

The exponent end error are caculated with the equations written in [1] page 4.

  url = {},
  author = {M.~E.~J. Newman},
  title = {Power laws, Pareto distributions and Zipf's law},
  journal = {Contemporary Physics},
  volume = {46},
  pages = {323},
  year = {2005},

  url = {},
  author = {Aaron Clauset and Cosma Rohilla Shalizi and M.~E.~J. Newman},
  title = {Power-law distributions in empirical data},
  year = {2007}
plot_powerlaw(gamma=None, **kwargs)

Plot a power law function with exponent gamma or self.gamma.

gamma: float, “cumulative” or None
if float, -gamma will be the exponent, if “cumulative” then -self.gamma+1 else -self.gamma.
Keyword argumentums are forwarded to the plot function.

Return with the plot.


Sets the type of binning, and calculates the binned distribution.

plot(plot=None, **kwargs)

Plot the bin smeared degree distribution.


Plot the bin smeared degree distribution with loglog scales (log scale in each axes).


Plot the bin smeared degree distribution with semilogy scales (log scale in y axis).


Plot the degree distribution with the fits.

summary(verbosity=0, file=None)

Write informations to screen or file about the distribution.


file: if string, it will be the name of the file,
if None (default), it will write to screen (stdout).
verbosity: integer (0,1,2), default 0
The bigger the value is, the more information you get.