Zum Inhalt

draw

dsstools.draw

Module for drawing network images through method chaining.

Copyright (C) 2024 dssTools Developers David Seseke david.seseke@uni-hamburg.de Katherine Shay katherine.shay@studium.uni-hamburg.de Professur Digitale Sozialwissenschaften Universität Hamburg

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Description

Class containing description drawing preferences.

set_text(text)

Sets the description setting.

Parameters:

Name Type Description Default
text
required

Returns:

Edges

Bases: GraphElement

set_sizes(arg)

Sets the sizes of the displayed edges.

Parameters:

Name Type Description Default
arg GenericMapping

int | list[int] | dict[tuple, int]: Widths to set. Integer values

required

Returns:

Type Description

self

GraphElement

set_alphas(arg)

Sets alpha based on argument.

Sets keyword if a string is passed, sets alpha for all labels if single float is passed, allows for multiple alpha values to be set if an array of floats is passed, allows for alphas to be individually set for labels based on the given node if a dictionary is passed

Parameters:

Name Type Description Default
None)

(default=None) The text transparency

required

set_colors(arg)

Sets the colors of the displayed nodes.

Parameters:

Name Type Description Default
arg GenericMapping

GenericMapping: Colors to set. String values

required

Returns:

Type Description

self

set_sizes(arg)

Sets size of labels for nodes as pt sizes.

Allows for multiple sizes to be set. arg (int or array of ints): (default=12) Font size for text labels

ImageGenerator

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.

Parameters:

Name Type Description Default
path str | Path

str | Path: Path to write the file to.

required

Returns:

Type Description

self

Labels

Bases: GraphElement

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 string, array of strings, dict of strings and integers
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

Nodes

Bases: GraphElement

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 | list[str] | dict[str, str]: Colors to set. String values

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

int | str | list[int] | dict[str, int]: sizes to set. Integer

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

int | str | list[int] | dict[str, int]: Sizes to set. Integer values

required

Returns:

Type Description

self