Zum Inhalt

draw

dsstools.draw

Module for drawing network images through method chaining.

Description()

Class containing description drawing preferences.

set_text(text)

Sets the description setting.

Parameters:

Name Type Description Default
text str

Text to set as description

required

Returns:

GraphElement

set_alphas(arg)

Sets alpha based on argument.

Parameters:

Name Type Description Default
arg GenericMapping | float

The text transparency as mapping between 0 and 1.

required

Returns: self

set_colors(arg)

Sets the colors of the displayed nodes.

Parameters:

Name Type Description Default
arg GenericMapping | str

Colors to set. String values will be mapped onto all nodes.

required

Returns:

Type Description

self

set_sizes(arg)

Sets size of labels for nodes as pt sizes.

Parameters:

Name Type Description Default
arg GenericMapping | int | float

Font size for text labels

required

Returns: self

set_transparency(arg)

Sets transparency based on argument.

This is the same as set_alphas(). Alpha is the value for the transparency of a color.

Parameters:

Name Type Description Default
arg GenericMapping | float

The text transparency as mapping between 0 and 1.

required

Returns: self

ImageGenerator(graph)

Base class for setting up image generation.

change_graph(graph)

Sets the graph attribute.

Parameters:

Name Type Description Default
graph

A NetworkX graph object.

required

Returns:

Type Description

self

deepcopy()

Create deep copy of the object.

This is the same as calling copy.deepcopy() on the object

draw_description()

Draw description below the image according to the settings.

draw_edges()

Draw edges according to the settings.

draw_labels()

Draws labels based on values.

draw_legend()

Not yet implemented.

draw_nodes()

Draw nodes according to the settings.

set_axis(axis)

Sets an existing matplotlib axis object for the ImageGenerator object.

Parameters:

Name Type Description Default
axis

Matplotlib axis

required

Returns:

Type Description

self

set_legend(legend=True)

Sets the legend setting.

Parameters:

Name Type Description Default
legend

(default = True) Whether to show the legend.

True

Returns:

Type Description

self

write_file(path)

Write file to disk on the given path.

Will also close the internal figure object.

Parameters:

Name Type Description Default
path str | Path

str | Path: Path to write the file to.

required

Returns:

Type Description

self

write_json(path)

Writes the graph data to a json file following nx.node_link_data format.

Parameters:

Name Type Description Default
path str | Path

saving location and name for the json-file

required

Returns:

Type Description
'ImageGenerator'

self

Labels()

Bases: GraphElement

set_alphas(arg)

Sets alpha based on argument.

Parameters:

Name Type Description Default
arg GenericMapping | float

The text transparency as mapping between 0 and 1.

required

Returns: self

set_colors(arg)

Sets the colors of the displayed nodes.

Parameters:

Name Type Description Default
arg GenericMapping | str

Colors to set. String values will be mapped onto all nodes.

required

Returns:

Type Description

self

set_font_families(arg)

Sets font family for all labels if single font is passed,.

Allows for multiple fonts to be set if an array of fonts is passed, allows for fonts to be individually set for labels based on the given node if a dictionary is passed.

Parameters:

Name Type Description Default
arg GenericMapping | str

Font family

required

set_labels(arg)

Sets labels for nodes based on arguments.

Parameters:

Name Type Description Default
arg dict

node identifier as the integer and the label as the string

required

set_sizes(arg)

Sets size of labels for nodes as pt sizes.

Parameters:

Name Type Description Default
arg GenericMapping | int | float

Font size for text labels

required

Returns: self

set_transparency(arg)

Sets transparency based on argument.

This is the same as set_alphas(). Alpha is the value for the transparency of a color.

Parameters:

Name Type Description Default
arg GenericMapping | float

The text transparency as mapping between 0 and 1.

required

Returns: self

Nodes(labels=None)

Bases: GraphElement

set_alphas(arg)

Sets alpha based on argument.

Parameters:

Name Type Description Default
arg GenericMapping | float

The text transparency as mapping between 0 and 1.

required

Returns: self

set_colors(arg)

Sets the colors of the displayed nodes.

Parameters:

Name Type Description Default
arg GenericMapping | str

Colors to set. String values will be mapped onto all nodes.

required

Returns:

Type Description

self

set_contour_colors(arg)

Sets the contour color of the displayed nodes.

Contour means the outer border of a node.

Parameters:

Name Type Description Default
arg GenericMapping | str

Colors to set. String values will be mapped onto all node contours. Additional options contain "node" and "edge" to automatically select the corresponding color.

required

Returns:

Type Description

self

set_contour_sizes(arg)

Sets the contour sizes of the displayed nodes.

Contour means the outer border of a node.

Parameters:

Name Type Description Default
arg GenericMapping | float | int

Sizes to set. Integer values will be mapped onto all node contours. String values will get mapped onto the corresponding data arrays or closeness values per node.

required

Returns:

Type Description

self

set_positions(pos)

Sets the node positions as a dict or list.

When using a file, use set_position_file() instead.

Parameters:

Name Type Description Default
pos dict | list | Path | str

dict | list: Array of positions. Dicts should be keyed by node ID.

required

Returns:

Type Description

self

set_sizes(arg)

Sets the sizes of the displayed nodes.

Parameters:

Name Type Description Default
arg GenericMapping | float | int

Sizes to set. Scalar values will be mapped onto all nodes. String values

required

Returns:

Type Description

self

set_transparency(arg)

Sets transparency based on argument.

This is the same as set_alphas(). Alpha is the value for the transparency of a color.

Parameters:

Name Type Description Default
arg GenericMapping | float

The text transparency as mapping between 0 and 1.

required

Returns: self

ensure_file_format(path, user_saving_format, *, default_format)

Ensures that the provided path has a saving format.

Parameters:

Name Type Description Default
path str | Path

the path that needs to be validated

required
user_saving_format str | None

the saving format provided by the user

required
default_format str

the format a programmer can set that will be used as default, if no format was provided at all

required

Returns:

Type Description
tuple[Path, str]

the filepath and format (without leading dot) as an 2-Tuple