Skip to content

plottingutils #

Useful code snippets for making commonly used plots in Raphtory.

Attributes#

motif_im_dir = Path(__file__).parents[1].absolute().as_posix() + '/motif-images/' module-attribute #

Functions#

global_motif_heatplot(motifs, cmap='YlGnBu', **kwargs) #

Out-of-the-box plotting of global motif counts corresponding to the layout in Motifs in Temporal Networks (Paranjape et al)

Parameters:

Name Type Description Default
motifs list | ndarray

1 dimensional length-40 array of motifs, which should be the list of motifs returned from the global_temporal_three_node_motifs function in Raphtory.

required
**kwargs

arguments to

{}

Returns:

Type Description
Axes

ax item containing the heatmap with motif labels on the axes.

to_motif_matrix(motifs, data_type=int) #

Converts a 40d vector of global motifs to a 2d grid of motifs corresponding to the layout in Motifs in Temporal Networks (Paranjape et al)

Parameters:

Name Type Description Default
motifs list | ndarray

1 dimensional length-40 array of motifs.

required

Returns:

Type Description
ndarray

6x6 array of motifs whose ijth element is M_ij in Motifs in Temporal Networks (Paranjape et al).

human_format(num) #

Converts a number over 1000 to a string with 1 d.p and the corresponding letter. e.g. with input 24134, 24.1k as a string would be returned. This is used in the motif plots to make annotated heatmap cells more concise.

Parameters:

Name Type Description Default
num int

number to be abbreviated

required

Returns:

Type Description
str

number in abbreviated string format.

cdf(observations, normalised=True) #

Returns x coordinates and y coordinates for a cdf (cumulative density function) from a list of observations.

Parameters:

Name Type Description Default
observations list

list of observations, should be numeric

required
normalised bool

if true, y coordinates normalised such that y is the probability of finding a value less than or equal to x, if false y is the number of observations less than or equal to x. Defaults to True.

True

Returns:

Type Description
Tuple[ndarray, ndarray]

the x and y coordinates for the cdf

ccdf(observations, normalised=True) #

Returns x coordinates and y coordinates for a ccdf (complementary cumulative density function) from a list of observations.

Parameters:

Name Type Description Default
observations list

list of observations, should be numeric

required
normalised (bool, optional)

Defaults to True. If true, y coordinates normalised such that y is the probability of finding a value greater than than or equal to x, if false y is the number of observations greater than or equal to x.

True

Returns:

Type Description
Tuple[ndarray, ndarray]

x and y coordinates for the cdf

lorenz(observations) #

Returns x coordinates and y coordinates for a Lorenz Curve from a list of observations.

Parameters:

Name Type Description Default
observations list

list of observations, should be numeric

required

Returns:

Type Description
Tuple[ndarray, ndarray]

x and y coordinates for the cdf

ordinal_number(number) #

Returns ordinal number of integer input.

Parameters:

Name Type Description Default
number int

input number

required

Returns:

Type Description
str

ordinal for that number as string