mercury.graph.viz
mercury.graph.viz.Moebius(G)
Bases: MoebiusAnywidget
Moebius class for visualizing graphs using an anywidget.
Important: This class requires: anywidget, traitlets and IPython.display!! These packages are not mandatory for the rest of the library, since you may not be intereseted in visualizing graphs. If you want to use this class, you need to install these packages.
Usage
from mercury.graph.viz import Moebius
G = ... # A graph object
moebius = Moebius(G)
moebius.show()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
G
|
Graph
|
The graph to be visualized. |
required |
Source code in mercury/graph/viz/moebius.py
522 523 524 525 526 |
|
__getitem__(item)
Add support for the [] operator.
Source code in mercury/graph/viz/moebius.py
129 130 131 132 133 134 |
|
__str__()
Convert the object via str()
Source code in mercury/graph/viz/moebius.py
121 122 123 124 125 126 |
|
generate_color_palette(cats, hue=0, sat=0.7, light=0.5)
Generates a color palette for the given categories. This can be used in combination with node_or_edge_config
to generate
the dictionary expected by the colors
argument with colors that cover the whole 0..1 hue range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cats
|
iterable
|
An iterable of categories for which the color palette is to be generated. |
required |
hue
|
float
|
The base hue that is added to all the colors in the color palette. It must be in range, 0..1, all the resulting hue values will be kept modulo 1.0. Default is 0 (no shift). |
0
|
sat
|
float
|
The saturation level for the colors. Default is 0.7. Range is 0..1. |
0.7
|
light
|
float
|
The lightness level for the colors. Default is 0.5. Range is 0..1. |
0.5
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary where keys are categories and values are hex color codes. |
Source code in mercury/graph/viz/moebius.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
node_or_edge_config(text_is=None, color_is=None, colors=None, size_is=None, size_range=None, size_scale='linear')
Create a node_config
or edge_config
configuration dictionary for show()
in an understandable way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text_is
|
str
|
The node/edge attribute to be displayed as text. Use the string |
None
|
color_is
|
str
|
A categorical node/edge attribute that can be represented as a color. This will also enable a legend interface where categories can be individually shown or hidden. |
None
|
colors
|
dict
|
The colors for each category defined as a dictionary. The keys are possible outcomes of category. The values are html RGB strings. E.g., .draw(category = 'size', colors = {'big' : '#c0a080', 'small' : '#a0c080'}) where 'big' and 'small' are possible values of the category 'size'. |
None
|
size_is
|
str
|
The node attribute to be displayed as the size of the nodes. Use the string |
None
|
size_range
|
List of two numbers
|
Combined with edge_label, this parameter controls the values in the variable that correspond to the minimum and maximum displayed sizes. The values below or equal the first value will be displayed with the base radius (that depends on the zoom) and the values above or equal to the second value will be shown with the maximum radius. |
None
|
size_scale
|
(linear, power, sqrt or log)
|
Combined with edge_label, the scale used to convert the value in the variable to the displayed radius. |
'linear'
|
Returns:
Type | Description |
---|---|
dict
|
The node configuration dictionary |
Source code in mercury/graph/viz/moebius.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
show(initial_id=None, initial_depth=1, node_config=None, edge_config=None)
Start the interactive graph visualization using an anywidget.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_id
|
str
|
The id of the node to start the visualization. |
None
|
initial_depth
|
int
|
The initial depth of the graph (starting with |
1
|
node_config
|
dict
|
A node configuration dictionary created by |
None
|
edge_config
|
dict
|
An edge configuration dictionary created by |
None
|
Source code in mercury/graph/viz/moebius.py
536 537 538 539 540 541 542 543 544 545 546 |
|