scivianna.plotter_2d package
Scivianna 2D Plotter Module
The plotter_2d module provides plotting backends for rendering two-dimensional geometries and field data in Scivianna. It supports both grid-based and polygon-based visualizations.
Files
File |
Description |
|---|---|
|
Package initialization file |
|
Public API exports for 2D plotting using matplotlib |
|
Base class |
|
Grid-based (raster) visualization backend |
|
Polygon-based vector visualization backend |
Submodules
Grid Backend (grid/)
Renders 2D data as colored grid cells:
bokeh.py: Bokeh-based interactive grid renderermatplotlib.py: Matplotlib static grid renderergrid_tools.py: Utility functions for grid manipulation
Polygon Backend (polygon/)
Renders 2D data as vector polygons:
bokeh.py: Bokeh-based interactive polygon renderermatplotlib.py: Matplotlib static polygon renderer
GenericPlotter2D (Base Class)
Defines the interface for all 2D plotters:
Key Methods
Method |
Purpose |
|---|---|
|
Create and return the Panel display object |
|
Update plot with new geometry and field data |
|
Set the color map for field visualization |
|
Set color scale limits |
|
Register mouse hover handler |
|
Register click handler |
Grid vs Polygon Rendering
Grid Renderer
Best for:
Regular grids
Large or complex datasets where polygons are hard to compute
Features:
Fast rendering for large datasets
Pixel-based display
Countour display
Polygon Renderer
Best for:
Unstructured meshes
Irregular cell geometries
When cell boundaries must be visible
Features:
Vector-based precise cell shapes
Cell boundary outlines
Hover/click per-cell detection
Interactive Features
Bokeh plotters can send back events when the mouse is moved or clicked on the geometry. Callback functions can be registered using the functions:
def provide_on_mouse_move_callback(self, callback: Callable):
def provide_on_clic_callback(self, callback: Callable):
Subpackages
- scivianna.plotter_2d.grid package
- Submodules
- scivianna.plotter_2d.grid.bokeh module
Bokeh2DGridPlotterBokeh2DGridPlotter.dim_hovered_cellBokeh2DGridPlotter.display_borders()Bokeh2DGridPlotter.display_edgesBokeh2DGridPlotter.export()Bokeh2DGridPlotter.get_resolution()Bokeh2DGridPlotter.make_panel()Bokeh2DGridPlotter.on_mouse_move()Bokeh2DGridPlotter.plot_2d_frame()Bokeh2DGridPlotter.provide_on_clic_callback()Bokeh2DGridPlotter.provide_on_mouse_move_callback()Bokeh2DGridPlotter.reset_hover()Bokeh2DGridPlotter.send_event()Bokeh2DGridPlotter.set_axes()Bokeh2DGridPlotter.set_color_map()Bokeh2DGridPlotter.update_2d_frame()Bokeh2DGridPlotter.update_colorbar()Bokeh2DGridPlotter.update_colors()Bokeh2DGridPlotter.update_plot_after_mouse_move()
- scivianna.plotter_2d.grid.grid_tools module
- scivianna.plotter_2d.grid.matplotlib module
Matplotlib2DGridPlotterMatplotlib2DGridPlotter.display_borders()Matplotlib2DGridPlotter.display_edgesMatplotlib2DGridPlotter.export()Matplotlib2DGridPlotter.get_resolution()Matplotlib2DGridPlotter.make_panel()Matplotlib2DGridPlotter.plot_2d_frame()Matplotlib2DGridPlotter.plot_2d_frame_in_axes()Matplotlib2DGridPlotter.set_axes()Matplotlib2DGridPlotter.set_color_map()Matplotlib2DGridPlotter.update_2d_frame()Matplotlib2DGridPlotter.update_colorbar()Matplotlib2DGridPlotter.update_colors()
- Module contents
- scivianna.plotter_2d.polygon package
- Submodules
- scivianna.plotter_2d.polygon.bokeh module
Bokeh2DPolygonPlotterBokeh2DPolygonPlotter.display_borders()Bokeh2DPolygonPlotter.export()Bokeh2DPolygonPlotter.get_resolution()Bokeh2DPolygonPlotter.make_panel()Bokeh2DPolygonPlotter.plot_2d_frame()Bokeh2DPolygonPlotter.provide_on_clic_callback()Bokeh2DPolygonPlotter.provide_on_mouse_move_callback()Bokeh2DPolygonPlotter.send_event()Bokeh2DPolygonPlotter.set_axes()Bokeh2DPolygonPlotter.set_color_map()Bokeh2DPolygonPlotter.update_2d_frame()Bokeh2DPolygonPlotter.update_colorbar()Bokeh2DPolygonPlotter.update_colors()
- scivianna.plotter_2d.polygon.matplotlib module
Matplotlib2DPolygonPlotterMatplotlib2DPolygonPlotter.display_borders()Matplotlib2DPolygonPlotter.export()Matplotlib2DPolygonPlotter.get_resolution()Matplotlib2DPolygonPlotter.make_panel()Matplotlib2DPolygonPlotter.plot_2d_frame()Matplotlib2DPolygonPlotter.plot_2d_frame_in_axes()Matplotlib2DPolygonPlotter.set_axes()Matplotlib2DPolygonPlotter.set_color_map()Matplotlib2DPolygonPlotter.update_2d_frame()Matplotlib2DPolygonPlotter.update_colorbar()Matplotlib2DPolygonPlotter.update_colors()
- Module contents
Submodules
scivianna.plotter_2d.api module
scivianna.plotter_2d.generic_plotter module
- class scivianna.plotter_2d.generic_plotter.Plotter2D
Bases:
objectGeneric 2D geometry plotter interface
- display_borders(display: bool)
Display or hides the figure borders and axis
- Parameters:
display (bool) – Display if true, hides otherwise
- enable_highlight(enable: bool = True)
Enable hover highlight
- Parameters:
enable (bool, optional) – Highlight enabled, by default True
- line_width = 1.0
Width of the line separating the different cells
- make_panel() Viewable
Makes the Holoviz panel viewable displayed in the web app.
- Returns:
Displayed viewable
- Return type:
pn.viewable.Viewable
- on_clic_callback = None
Function to call when the mouse is clicked on the geometry
- on_mouse_move_callback = None
Function to call when the mouse is moved on the geometry
- plot_2d_frame(data: Data2D)
Adds a new plot to the figure from a set of polygons
- Parameters:
data (Data2D) – Data2D object containing the geometry to plot
- provide_on_clic_callback(callback: Callable)
Stores a function to call everytime the user clics on the plot. Functions arguments are location, cell_id.
- Parameters:
callback (Callable) – Function to call.
- provide_on_mouse_move_callback(callback: Callable)
Stores a function to call everytime the user moves the mouse on the plot. Functions arguments are location, cell_id.
- Parameters:
callback (Callable) – Function to call.
- set_axes(u: Tuple[float, float, float], v: Tuple[float, float, float], w: float)
Stores the u v axes of the current plot
- Parameters:
u (Tuple[float, float, float]) – Horizontal axis direction vector
v (Tuple[float, float, float]) – Vertical axis direction vector
w (float) – Normal vector coordinate
- set_color_map(color_map_name: str)
Sets the colorbar color map name
- Parameters:
color_map_name (str) – Color map name
- update_2d_frame(data: Data2D)
Updates plot to the figure
- Parameters:
data (Data2D) – Data2D object containing the data to update
- update_colorbar(display: bool, range: Tuple[float, float])
Displays or hide the color bar, if display, updates its range
- Parameters:
display (bool) – Display or hides the color bar
range (Tuple[float, float]) – New colormap range