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

__init__.py

Package initialization file

api.py

Public API exports for 2D plotting using matplotlib

generic_plotter.py

Base class GenericPlotter2D defining the 2D plotting API

grid/

Grid-based (raster) visualization backend

polygon/

Polygon-based vector visualization backend

Submodules

Grid Backend (grid/)

Renders 2D data as colored grid cells:

  • bokeh.py: Bokeh-based interactive grid renderer

  • matplotlib.py: Matplotlib static grid renderer

  • grid_tools.py: Utility functions for grid manipulation

Polygon Backend (polygon/)

Renders 2D data as vector polygons:

  • bokeh.py: Bokeh-based interactive polygon renderer

  • matplotlib.py: Matplotlib static polygon renderer

GenericPlotter2D (Base Class)

Defines the interface for all 2D plotters:

Key Methods

Method

Purpose

make_panel()

Create and return the Panel display object

update_geometry(cells, values)

Update plot with new geometry and field data

set_colormap(colormap)

Set the color map for field visualization

set_clim(vmin, vmax)

Set color scale limits

provide_on_mouse_move_callback(fn)

Register mouse hover handler

provide_on_clic_callback(fn)

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

Submodules

scivianna.plotter_2d.api module

scivianna.plotter_2d.generic_plotter module

class scivianna.plotter_2d.generic_plotter.Plotter2D

Bases: object

Generic 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

update_colors(data: Data2D)

Updates the colors of the displayed polygons

Parameters:

data (Data2D) – Data2D object containing the data to update

Module contents