Plot backends
Base
Abstract base class for plot backends.
AbstractSomPlot
Bases: ABC
SomPlot.
Source code in src/somap/plot_backends/base.py
__init__(som, *, show_prototypes=True, show_activity=False, **kwargs)
abstractmethod
Creates a SomPlot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
som |
Self-Organizing Map as a Som object. |
required | |
args |
Positional arguments passed to the |
required | |
show_prototypes |
Show prototypes of each node as an image. |
True
|
|
show_activity |
Show activity value of each node as a color. |
False
|
|
kwargs |
Keyword arguments passed to the |
{}
|
Source code in src/somap/plot_backends/base.py
plot()
abstractmethod
Altair
Altair plot backends.
SomPlot
Bases: AbstractSomPlot
SomPlot.
Source code in src/somap/plot_backends/altair.py
__init__(som, *, show_prototypes=True, show_activity=False, **kwargs)
Creates a SomPlot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
som |
AbstractSom
|
Self-Organizing Map as a Som object. |
required |
args |
Positional arguments passed to the |
required | |
show_prototypes |
Show prototypes of each node as an image. |
True
|
|
show_activity |
Show activity value of each node as a color. |
False
|
|
kwargs |
Keyword arguments passed to the |
{}
|
Source code in src/somap/plot_backends/altair.py
plot()
plot(data, shape, topography, *, bin_size_scale=1.0, w_scale=1.0, h_scale=1.0, values=True, images=True, tooltip=True, color_scale=alt.Scale(scheme='lighttealblue'), color_legend=None, title=None)
Return an Altair chart containing shape[0] * shape[1] hexagons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Pandas dataframe with the following columns: x: Horizontal coordinate in the hex grid. y: Vertical coordonates in the hex grid. values: one scalar value per hexagon (optional). images: one encoded image per hexagon (optional). image: one encoded image per hexagon (for tooltip) (optional). infos: one text value per hexagon(optional). |
required |
shape |
tuple[int, int]
|
column and line numbers of the hex grid. |
required |
topography |
str
|
Topography of the 2D map, either 'square' or 'hex'. |
required |
bin_size_scale |
float
|
size of the hexagons. |
1.0
|
w_scale |
float
|
horizontal scaling factor (sometimes needed to go around rendering bugs of external libs). |
1.0
|
h_scale |
float
|
vertical scaling factor (sometimes needed to go around rendering bugs of external libs). |
1.0
|
values |
bool
|
if True, fill the hexagons with a color corresponding to data['values']. |
True
|
images |
bool
|
if True, show the image of all hexagon with an image corresponding to data['images']. |
True
|
tooltip |
bool
|
if True, show an interactive tooltip given detailed values of the selected hexagon |
True
|
color_scale |
Scale
|
color scale used if color is True. Continous scale from light blue to dark blue by default. |
Scale(scheme='lighttealblue')
|
color_legend |
Legend | None
|
arr color legend used if color is True. Dynamic legend by default. (set to 'None' to hide the legend). |
None
|
title |
str | None
|
Title of the plot. |
None
|
Returns:
Type | Description |
---|---|
LayerChart
|
The altair chart. |
Source code in src/somap/plot_backends/altair.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 166 167 168 169 170 171 |
|
Array2image
Array2image plot backends.
SomPlot
Bases: AbstractSomPlot
SomPlot.
Source code in src/somap/plot_backends/array2image.py
__init__(som, *, show_prototypes=True, show_activity=False, **kwargs)
Creates a SomPlot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
som |
AbstractSom
|
Self-Organizing Map as a Som object. |
required |
args |
Positional arguments passed to the |
required | |
show_prototypes |
Show prototypes of each node as an image. |
True
|
|
show_activity |
Show activity value of each node as a color. |
False
|
|
kwargs |
Keyword arguments passed to the |
{}
|
Source code in src/somap/plot_backends/array2image.py
plot()
add_text_border(image, text, border_height=50, font_size=20, font_path=FONT_PATH)
Adds a header with a text to an image.