Visualization
dissmodel.visualization.Chart
Bases: Model
Simulation model that renders a live time-series chart.
Extends :class:~dissmodel.core.Model and redraws the chart at every
time step. Supports three rendering targets:
- Streamlit — pass a
plot_area(st.empty()). - Jupyter — detected automatically via :func:
is_notebook. - Matplotlib window — fallback for plain Python scripts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
select
|
list of str
|
Subset of labels to plot. If |
required |
pause
|
bool
|
If |
required |
plot_area
|
any
|
Streamlit |
required |
show_legend
|
bool
|
Whether to display the plot legend, by default |
required |
show_grid
|
bool
|
Whether to display the plot grid, by default |
required |
title
|
str
|
Chart title, by default |
required |
Examples:
>>> env = Environment(end_time=30)
>>> Chart(show_legend=True, show_grid=True, title="SIR Model")
>>> env.run()
Source code in dissmodel/visualization/chart.py
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 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 | |
execute()
Redraw the chart for the current simulation time step.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no interactive matplotlib backend is detected and the code is not running in a notebook or Streamlit context. |
Source code in dissmodel/visualization/chart.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 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 | |
setup(select=None, pause=True, plot_area=None, show_legend=True, show_grid=False, title='Variable History')
Configure the chart.
Called automatically by salabim during component initialisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
select
|
list of str
|
Subset of labels to plot. If |
None
|
pause
|
bool
|
If |
True
|
plot_area
|
any
|
Streamlit |
None
|
show_legend
|
bool
|
Whether to display the plot legend, by default |
True
|
show_grid
|
bool
|
Whether to display the plot grid, by default |
False
|
title
|
str
|
Chart title, by default |
'Variable History'
|
Source code in dissmodel/visualization/chart.py
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 | |
dissmodel.visualization.map.Map
Bases: Model
Simulation model that renders a live choropleth map.
Extends :class:~dissmodel.core.Model and redraws the map at every
time step. Supports three rendering targets:
- Streamlit — pass a
plot_area(st.empty()). - Jupyter — detected automatically via :func:
is_notebook. - Matplotlib window — fallback for plain Python scripts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to render. |
required |
plot_params
|
dict
|
Keyword arguments forwarded to :meth: |
required |
pause
|
bool
|
If |
required |
plot_area
|
any
|
Streamlit |
required |
Examples:
>>> env = Environment(end_time=10)
>>> Map(gdf=grid, plot_params={"column": "state", "cmap": "viridis"})
>>> env.run()
Source code in dissmodel/visualization/map.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 | |
execute()
Redraw the map for the current simulation time step.
Source code in dissmodel/visualization/map.py
134 135 136 | |
setup(gdf, plot_params, pause=True, plot_area=None)
Configure the map.
Called automatically by salabim during component initialisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame to render. |
required |
plot_params
|
dict
|
Keyword arguments forwarded to :meth: |
required |
pause
|
bool
|
If |
True
|
plot_area
|
any
|
Streamlit |
None
|
Source code in dissmodel/visualization/map.py
52 53 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 | |
update(year, gdf)
Redraw the map for a given simulation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
float
|
Current simulation time, displayed in the map title. |
required |
gdf
|
GeoDataFrame
|
GeoDataFrame snapshot to render. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no interactive matplotlib backend is detected and the code is not running in a notebook or Streamlit context. |
Source code in dissmodel/visualization/map.py
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 | |
dissmodel.visualization.widgets.display_inputs(obj, st)
Render Streamlit input widgets for every annotated attribute on obj.
Iterates over obj.__annotations__ and creates an appropriate widget
for each attribute based on its current value type. The attribute is
updated in-place on obj after each interaction.
Widget mapping:
bool→st.checkbox(checked before int — bool subclasses int)int→st.slider(0 – 1000)float→st.slider(0.0 – 1.0, step 0.01)- anything else →
st.text_input
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
any
|
Any object with |
required |
st
|
any
|
Streamlit module or sidebar object (e.g. |
required |
Examples:
>>> display_inputs(sir_model, st.sidebar)
>>> display_inputs(ca_model, st)
Source code in dissmodel/visualization/widgets.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
dissmodel.visualization.track_plot(label, color, plot_type='line')
Class decorator that registers an attribute for live plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Display label and lookup key for the tracked attribute. |
required |
color
|
str
|
Matplotlib-compatible color string (e.g. |
required |
plot_type
|
str
|
Plot style, by default |
'line'
|
Returns:
| Type | Description |
|---|---|
type
|
The decorated class with |
Examples:
>>> @track_plot(label="Infected", color="red")
... class SIR(Model):
... infected: int = 0
Source code in dissmodel/visualization/chart.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |