GSP Matplotlib API Reference¶
The GSP Matplotlib backend provides rendering using the Matplotlib library, enabling integration with the Python scientific visualization ecosystem.
Overview¶
gsp_matplotlib
¶
GSP Matplotlib package initialization.
Renderer Module¶
The renderer module contains the main Matplotlib renderer implementation and specialized renderers for different visual types.
gsp_matplotlib.renderer
¶
Matplotlib Renderer Package.
MatplotlibRenderer
¶
Bases: gsp.types.renderer_base.RendererBase
Matplotlib-based renderer for GSP visuals.
This renderer implements the GSP rendering interface using Matplotlib as the backend. It creates and manages a Matplotlib figure with multiple axes for different viewports, and renders various visual types (pixels, points, paths, markers, segments, texts) into them.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
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 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
__init__(canvas: Canvas)
¶
Initialize the Matplotlib renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canvas
|
gsp.core.canvas.Canvas
|
The canvas defining the rendering surface dimensions and DPI. |
required |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
get_canvas() -> Canvas
¶
Get the canvas associated with this renderer.
Returns:
| Type | Description |
|---|---|
gsp.core.canvas.Canvas
|
The canvas instance. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
65 66 67 68 69 70 71 | |
close() -> None
¶
Close the renderer and release resources.
Stops the Matplotlib event loop and closes the figure.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
73 74 75 76 77 78 79 80 81 82 83 | |
show() -> None
¶
Display the rendered figure in an interactive window.
This method shows the Matplotlib figure. It does nothing when running in test mode (GSP_TEST environment variable set to "True").
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
render(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera], return_image: bool = True, image_format: str = 'png') -> bytes
¶
Render the scene to an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
Sequence of viewport regions to render into. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
Sequence of visual elements to render. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
Sequence of model transformation matrices for each visual. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
Sequence of cameras defining view and projection for each visual. |
required |
return_image
|
bool
|
Whether to return the rendered image as bytes. |
True
|
image_format
|
str
|
Format for the output image (e.g., "png", "jpg"). |
'png'
|
Returns:
| Type | Description |
|---|---|
bytes
|
The rendered image as bytes in the specified format, or empty bytes if return_image is False. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the sequences don't all have the same length. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
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 | |
get_mpl_axes_for_viewport(viewport: Viewport) -> matplotlib.axes.Axes
¶
Get the Matplotlib axes associated with a viewport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewport
|
gsp.core.viewport.Viewport
|
The viewport to get axes for. |
required |
Returns:
| Type | Description |
|---|---|
matplotlib.axes.Axes
|
The Matplotlib Axes object for the given viewport. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
215 216 217 218 219 220 221 222 223 224 | |
get_mpl_figure() -> matplotlib.figure.Figure
¶
Get the underlying Matplotlib figure.
Returns:
| Type | Description |
|---|---|
matplotlib.figure.Figure
|
The Matplotlib Figure object used by this renderer. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
226 227 228 229 230 231 232 | |
Matplotlib Renderer¶
gsp_matplotlib.renderer.matplotlib_renderer
¶
Matplotlib renderer for GSP visuals.
MatplotlibRenderer
¶
Bases: gsp.types.renderer_base.RendererBase
Matplotlib-based renderer for GSP visuals.
This renderer implements the GSP rendering interface using Matplotlib as the backend. It creates and manages a Matplotlib figure with multiple axes for different viewports, and renders various visual types (pixels, points, paths, markers, segments, texts) into them.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
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 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
__init__(canvas: Canvas)
¶
Initialize the Matplotlib renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canvas
|
gsp.core.canvas.Canvas
|
The canvas defining the rendering surface dimensions and DPI. |
required |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
close() -> None
¶
Close the renderer and release resources.
Stops the Matplotlib event loop and closes the figure.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
73 74 75 76 77 78 79 80 81 82 83 | |
get_canvas() -> Canvas
¶
Get the canvas associated with this renderer.
Returns:
| Type | Description |
|---|---|
gsp.core.canvas.Canvas
|
The canvas instance. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
65 66 67 68 69 70 71 | |
get_mpl_axes_for_viewport(viewport: Viewport) -> matplotlib.axes.Axes
¶
Get the Matplotlib axes associated with a viewport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewport
|
gsp.core.viewport.Viewport
|
The viewport to get axes for. |
required |
Returns:
| Type | Description |
|---|---|
matplotlib.axes.Axes
|
The Matplotlib Axes object for the given viewport. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
215 216 217 218 219 220 221 222 223 224 | |
get_mpl_figure() -> matplotlib.figure.Figure
¶
Get the underlying Matplotlib figure.
Returns:
| Type | Description |
|---|---|
matplotlib.figure.Figure
|
The Matplotlib Figure object used by this renderer. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
226 227 228 229 230 231 232 | |
render(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera], return_image: bool = True, image_format: str = 'png') -> bytes
¶
Render the scene to an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
Sequence of viewport regions to render into. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
Sequence of visual elements to render. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
Sequence of model transformation matrices for each visual. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
Sequence of cameras defining view and projection for each visual. |
required |
return_image
|
bool
|
Whether to return the rendered image as bytes. |
True
|
image_format
|
str
|
Format for the output image (e.g., "png", "jpg"). |
'png'
|
Returns:
| Type | Description |
|---|---|
bytes
|
The rendered image as bytes in the specified format, or empty bytes if return_image is False. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the sequences don't all have the same length. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
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 | |
show() -> None
¶
Display the rendered figure in an interactive window.
This method shows the Matplotlib figure. It does nothing when running in test mode (GSP_TEST environment variable set to "True").
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
Markers Renderer¶
gsp_matplotlib.renderer.matplotlib_renderer_markers
¶
Matplotlib renderer for Markers objects.
RendererMarkers
¶
Renderer for Markers objects using Matplotlib.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_markers.py
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 | |
render(renderer: MatplotlibRenderer, viewport: Viewport, markers: Markers, model_matrix: TransBuf, camera: Camera) -> list[matplotlib.artist.Artist]
staticmethod
¶
Render the given Markers object onto the specified viewport using Matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.matplotlib_renderer.MatplotlibRenderer
|
The renderer instance. |
required |
viewport
|
gsp.core.viewport.Viewport
|
The viewport to render onto. |
required |
markers
|
gsp.visuals.Markers
|
The Markers object containing marker data. |
required |
model_matrix
|
gsp.types.transbuf.TransBuf
|
The model transformation matrix. |
required |
camera
|
gsp.core.camera.Camera
|
The camera providing view and projection matrices. |
required |
Returns:
| Type | Description |
|---|---|
list[matplotlib.artist.Artist]
|
list[matplotlib.artist.Artist]: A list of Matplotlib artist objects created or updated |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_markers.py
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 | |
Paths Renderer¶
gsp_matplotlib.renderer.matplotlib_renderer_paths
¶
Matplotlib renderer for Paths objects.
RendererPaths
¶
Renderer for Paths objects using Matplotlib.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_paths.py
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
render(renderer: MatplotlibRenderer, viewport: Viewport, paths: Paths, model_matrix: TransBuf, camera: Camera) -> list[matplotlib.artist.Artist]
staticmethod
¶
Render the given Paths object onto the specified viewport using Matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.matplotlib_renderer.MatplotlibRenderer
|
The renderer instance. |
required |
viewport
|
gsp.core.viewport.Viewport
|
The viewport to render onto. |
required |
paths
|
gsp.visuals.paths.Paths
|
The Paths object containing path data. |
required |
model_matrix
|
gsp.types.transbuf.TransBuf
|
The model transformation matrix. |
required |
camera
|
gsp.core.camera.Camera
|
The camera providing view and projection matrices. |
required |
Returns:
| Type | Description |
|---|---|
list[matplotlib.artist.Artist]
|
list[matplotlib.artist.Artist]: A list of Matplotlib artist objects created or updated |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_paths.py
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
Pixels Renderer¶
gsp_matplotlib.renderer.matplotlib_renderer_pixels
¶
Renderer for Pixels using Matplotlib.
RendererPixels
¶
Renderer for Pixels using Matplotlib.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_pixels.py
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 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 | |
create_artists(renderer: MatplotlibRenderer, viewport: Viewport, visual: VisualBase, group_count: int) -> None
staticmethod
¶
Create the artists associated with the given visual and group count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.MatplotlibRenderer
|
The Matplotlib renderer. |
required |
viewport
|
gsp.core.viewport.Viewport
|
The viewport for which to create the artists. |
required |
visual
|
gsp.types.visual_base.VisualBase
|
The visual for which to create the artists. |
required |
group_count
|
int
|
The number of groups in the visual. |
required |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_pixels.py
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 | |
destroy_artists(renderer: MatplotlibRenderer, viewport: Viewport, visual: VisualBase, group_count: int) -> None
staticmethod
¶
Destroy the artists associated with the given visual and group count.
Trigger a bug in matplotlib where artists are not properly removed from the axes.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_pixels.py
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 | |
render(renderer: MatplotlibRenderer, viewport: Viewport, pixels: Pixels, model_matrix: TransBuf, camera: Camera) -> list[matplotlib.artist.Artist]
staticmethod
¶
Render Pixels visual using Matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.MatplotlibRenderer
|
The MatplotlibRenderer instance. |
required |
viewport
|
gsp.core.viewport.Viewport
|
The Viewport in which to render. |
required |
pixels
|
gsp.visuals.pixels.Pixels
|
The Pixels visual to render. |
required |
model_matrix
|
gsp.types.transbuf.TransBuf
|
The model transformation matrix as a TransBuf. |
required |
camera
|
gsp.core.camera.Camera
|
The Camera providing view and projection matrices. |
required |
Returns:
| Type | Description |
|---|---|
list[matplotlib.artist.Artist]
|
list[matplotlib.artist.Artist]: List of Matplotlib artists created/updated. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_pixels.py
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 | |
Points Renderer¶
gsp_matplotlib.renderer.matplotlib_renderer_points
¶
Renderer for Points using Matplotlib.
RendererPoints
¶
Renderer for Points using Matplotlib.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_points.py
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 | |
render(renderer: MatplotlibRenderer, viewport: Viewport, points: Points, model_matrix: TransBuf, camera: Camera) -> list[matplotlib.artist.Artist]
staticmethod
¶
Render Points visual using Matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.matplotlib_renderer.MatplotlibRenderer
|
The MatplotlibRenderer instance. |
required |
viewport
|
gsp.core.viewport.Viewport
|
The Viewport in which to render. |
required |
points
|
gsp.visuals.points.Points
|
The Points visual to render. |
required |
model_matrix
|
gsp.types.transbuf.TransBuf
|
The model transformation matrix as a TransBuf. |
required |
camera
|
gsp.core.camera.Camera
|
The Camera providing view and projection matrices. |
required |
Returns:
| Type | Description |
|---|---|
list[matplotlib.artist.Artist]
|
list[matplotlib.artist.Artist]: List of Matplotlib artists created/updated. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_points.py
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 | |
Segments Renderer¶
gsp_matplotlib.renderer.matplotlib_renderer_segments
¶
Renderer for Segments using Matplotlib.
RendererSegments
¶
Renderer for Segments using Matplotlib.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_segments.py
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 | |
render(renderer: MatplotlibRenderer, viewport: Viewport, segments: Segments, model_matrix: TransBuf, camera: Camera) -> list[matplotlib.artist.Artist]
staticmethod
¶
Render Segments visual using Matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.matplotlib_renderer.MatplotlibRenderer
|
The MatplotlibRenderer instance. |
required |
viewport
|
gsp.core.viewport.Viewport
|
The Viewport in which to render. |
required |
segments
|
gsp.visuals.segments.Segments
|
The Segments visual to render. |
required |
model_matrix
|
gsp.types.transbuf.TransBuf
|
The model transformation matrix as a TransBuf. |
required |
camera
|
gsp.core.camera.Camera
|
The Camera providing view and projection matrices. |
required |
Returns:
| Type | Description |
|---|---|
list[matplotlib.artist.Artist]
|
list[matplotlib.artist.Artist]: List of Matplotlib artists created/updated. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_segments.py
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 | |
Texts Renderer¶
gsp_matplotlib.renderer.matplotlib_renderer_texts
¶
Renderer for Texts using Matplotlib.
RendererTexts
¶
Renderer for Texts using Matplotlib.
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_texts.py
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
render(renderer: MatplotlibRenderer, viewport: Viewport, texts: Texts, model_matrix: TransBuf, camera: Camera) -> list[matplotlib.artist.Artist]
staticmethod
¶
Render Texts visual using Matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.matplotlib_renderer.MatplotlibRenderer
|
The MatplotlibRenderer instance. |
required |
viewport
|
gsp.core.viewport.Viewport
|
The Viewport in which to render. |
required |
texts
|
gsp.visuals.texts.Texts
|
The Texts visual to render. |
required |
model_matrix
|
gsp.types.transbuf.TransBuf
|
The model transformation matrix as a TransBuf. |
required |
camera
|
gsp.core.camera.Camera
|
The Camera providing view and projection matrices. |
required |
Returns:
| Type | Description |
|---|---|
list[matplotlib.artist.Artist]
|
list[matplotlib.artist.Artist]: List of Matplotlib artists created/updated. |
Source code in src/gsp_matplotlib/renderer/matplotlib_renderer_texts.py
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
Extra Module¶
The extra module provides additional utilities and extensions for Matplotlib rendering.
gsp_matplotlib.extra
¶
GSP Matplotlib extra utilities package initialization.
Bufferx
¶
Utility class for Buffer extended functionality using numpy.
Source code in src/gsp_matplotlib/extra/bufferx.py
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 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 | |
mat4_identity() -> Buffer
staticmethod
¶
Create a Buffer containing a 4x4 identity matrix.
Source code in src/gsp_matplotlib/extra/bufferx.py
14 15 16 17 18 19 | |
to_numpy(buffer: Buffer) -> np.ndarray
staticmethod
¶
Convert a Buffer to a numpy array.
Source code in src/gsp_matplotlib/extra/bufferx.py
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 | |
from_numpy(array_numpy: np.ndarray, bufferType: BufferType) -> Buffer
staticmethod
¶
Create a Buffer from a numpy array.
Source code in src/gsp_matplotlib/extra/bufferx.py
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 | |
Bufferx¶
gsp_matplotlib.extra.bufferx
¶
Utility class for Buffer extended functionality using numpy.
Bufferx
¶
Utility class for Buffer extended functionality using numpy.
Source code in src/gsp_matplotlib/extra/bufferx.py
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 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 | |
from_numpy(array_numpy: np.ndarray, bufferType: BufferType) -> Buffer
staticmethod
¶
Create a Buffer from a numpy array.
Source code in src/gsp_matplotlib/extra/bufferx.py
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 | |
mat4_identity() -> Buffer
staticmethod
¶
Create a Buffer containing a 4x4 identity matrix.
Source code in src/gsp_matplotlib/extra/bufferx.py
14 15 16 17 18 19 | |
to_numpy(buffer: Buffer) -> np.ndarray
staticmethod
¶
Convert a Buffer to a numpy array.
Source code in src/gsp_matplotlib/extra/bufferx.py
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 | |
Utils Module¶
The utils module provides converter utilities for the Matplotlib backend.
gsp_matplotlib.utils
¶
Utility module for GSP Matplotlib conversions.
ConverterUtils
¶
Utility class for converting GSP types to Matplotlib types.
Source code in src/gsp_matplotlib/utils/converter_utils.py
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
cap_style_gsp_to_mpl(gsp_cap_style: CapStyle) -> Literal['butt', 'round', 'projecting']
staticmethod
¶
Convert CapStyle enum to Matplotlib string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gsp_cap_style
|
gsp.types.CapStyle
|
The GSP cap style. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
typing.Literal['butt', 'round', 'projecting']
|
The corresponding Matplotlib cap style. |
Source code in src/gsp_matplotlib/utils/converter_utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
join_style_gsp_to_mpl(gsp_join_style: JoinStyle) -> Literal['miter', 'round', 'bevel']
staticmethod
¶
Convert JoinStyle enum to Matplotlib string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gsp_join_style
|
gsp.types.JoinStyle
|
The GSP join style. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
typing.Literal['miter', 'round', 'bevel']
|
The corresponding Matplotlib join style. |
Source code in src/gsp_matplotlib/utils/converter_utils.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
marker_shape_gsp_to_mpl(gsp_marker_shape: MarkerShape) -> str
staticmethod
¶
Convert GSP marker shape to Matplotlib marker shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gsp_marker_shape
|
gsp.types.MarkerShape
|
The GSP marker shape. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The corresponding Matplotlib marker shape. |
Source code in src/gsp_matplotlib/utils/converter_utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
Converter Utils¶
gsp_matplotlib.utils.converter_utils
¶
Utility class for converting GSP types to Matplotlib types.
ConverterUtils
¶
Utility class for converting GSP types to Matplotlib types.
Source code in src/gsp_matplotlib/utils/converter_utils.py
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
cap_style_gsp_to_mpl(gsp_cap_style: CapStyle) -> Literal['butt', 'round', 'projecting']
staticmethod
¶
Convert CapStyle enum to Matplotlib string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gsp_cap_style
|
gsp.types.CapStyle
|
The GSP cap style. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
typing.Literal['butt', 'round', 'projecting']
|
The corresponding Matplotlib cap style. |
Source code in src/gsp_matplotlib/utils/converter_utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
join_style_gsp_to_mpl(gsp_join_style: JoinStyle) -> Literal['miter', 'round', 'bevel']
staticmethod
¶
Convert JoinStyle enum to Matplotlib string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gsp_join_style
|
gsp.types.JoinStyle
|
The GSP join style. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
typing.Literal['miter', 'round', 'bevel']
|
The corresponding Matplotlib join style. |
Source code in src/gsp_matplotlib/utils/converter_utils.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
marker_shape_gsp_to_mpl(gsp_marker_shape: MarkerShape) -> str
staticmethod
¶
Convert GSP marker shape to Matplotlib marker shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gsp_marker_shape
|
gsp.types.MarkerShape
|
The GSP marker shape. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The corresponding Matplotlib marker shape. |
Source code in src/gsp_matplotlib/utils/converter_utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
Viewport Events Matplotlib¶
gsp_matplotlib.viewport_events.viewport_events_matplotlib
¶
MatplotlibRenderer event handler for viewport events.
ViewportEventsMatplotlib
¶
Bases: gsp.types.viewport_events_base.ViewportEventsBase
MatplotlibRenderer event handler for viewport.
Source code in src/gsp_matplotlib/viewport_events/viewport_events_matplotlib.py
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 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 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
__init__(renderer: MatplotlibRenderer, viewport: Viewport) -> None
¶
Initialize the Matplotlib viewport event handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.MatplotlibRenderer
|
MatplotlibRenderer associated with this event handler. |
required |
viewport
|
gsp.core.Viewport
|
Viewport associated with this event handler. |
required |
Source code in src/gsp_matplotlib/viewport_events/viewport_events_matplotlib.py
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 | |
close()
¶
Close the event handler and release resources.
Source code in src/gsp_matplotlib/viewport_events/viewport_events_matplotlib.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
Animator Matplotlib¶
gsp_matplotlib.animator.animator_matplotlib
¶
Matplotlib-based animator for GSP scenes.
Provides animation capabilities using a MatplotlibRenderer backend with support for real-time animation display and video export.
AnimatorMatplotlib
¶
Bases: gsp.types.animator_base.AnimatorBase
Animator for GSP scenes using a Matplotlib renderer.
Manages animation loops with callback functions that update visuals each frame. Supports real-time display and video export in various formats. Uses Matplotlib's FuncAnimation for efficient rendering updates.
Source code in src/gsp_matplotlib/animator/animator_matplotlib.py
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 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
on_video_saved = Event[VideoSavedCalledback]()
instance-attribute
¶
Event triggered when the video has been successfully saved to disk.
__init__(matplotlib_renderer: MatplotlibRenderer, fps: int = 50, video_duration: float = 10.0, video_path: str | None = None, video_writer: str | None = None)
¶
Initialize the Matplotlib animator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matplotlib_renderer
|
gsp_matplotlib.renderer.MatplotlibRenderer
|
The Matplotlib renderer to use for rendering frames. |
required |
fps
|
int
|
Target frames per second for the animation. |
50
|
video_duration
|
float
|
Total duration of the animation in seconds. |
10.0
|
video_path
|
str | None
|
Path where the video should be saved. If None, no video is saved. |
None
|
video_writer
|
str | None
|
Video writer to use ("ffmpeg" or "pillow"). If None, auto-detected from extension. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the video format is not supported. |
Source code in src/gsp_matplotlib/animator/animator_matplotlib.py
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 | |
add_callback(func: AnimatorFunc) -> None
¶
Add a callback to the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp.types.animator_types.AnimatorFunc
|
The animator function to call on each frame. |
required |
Source code in src/gsp_matplotlib/animator/animator_matplotlib.py
101 102 103 104 105 106 107 | |
event_listener(func: AnimatorFunc) -> AnimatorFunc
¶
Decorator to add a callback to the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp.types.animator_types.AnimatorFunc
|
The animator function to register as a callback. |
required |
Returns:
| Type | Description |
|---|---|
gsp.types.animator_types.AnimatorFunc
|
The wrapped animator function. |
Usage
@animation_loop.event_listener
def my_callback(delta_time: float) -> Sequence[VisualBase]:
...
# later, if needed
animation_loop.remove_callback(my_callback)
Source code in src/gsp_matplotlib/animator/animator_matplotlib.py
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 | |
remove_callback(func: AnimatorFunc) -> None
¶
Remove a callback from the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp.types.animator_types.AnimatorFunc
|
The animator function to remove. |
required |
Source code in src/gsp_matplotlib/animator/animator_matplotlib.py
109 110 111 112 113 114 115 | |
start(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> None
¶
Start the animation loop.
Begins rendering frames using registered callbacks to update visuals. In test mode (GSP_TEST=True), saves a single preview image instead of animating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
Sequence of viewport regions to render into. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
Sequence of visual elements to render and animate. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
Sequence of model transformation matrices. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
Sequence of cameras defining view and projection. |
required |
Source code in src/gsp_matplotlib/animator/animator_matplotlib.py
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 214 215 216 217 218 219 220 221 222 223 224 225 | |
stop()
¶
Stop the animation loop.
Stops the Matplotlib animation timer and clears internal state.
Source code in src/gsp_matplotlib/animator/animator_matplotlib.py
230 231 232 233 234 235 236 237 238 239 240 241 242 | |