lepy / stpyvista

🧊 Show pyvista 3D visualizations in streamlit

Home Page:https://stpyvista.streamlit.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🧊 stpyvista

Show PyVista 3D visualizations in Streamlit

Streamlit Cloud

Github Repo PyPi version Github tests repo

howto-stpyvista|508x500, 100%

This is a simple component that takes a PyVista plotter object and shows it on Streamlit as an interactive element (as in it can be zoomed in/out, moved and rotated, but the visualization state is not returned). It uses PyVista's panel backend and it basically takes the plotter, exports it to HTML and displays that within an iframe.

⚠️ panel and pythreejs as pyvista backends were deprecated in favor of trame.


Installation

pip install stpyvista

Docs and examples

Streamlit App


Basic example:

import streamlit as st
import pyvista as pv
from stpyvista import stpyvista

# pythreejs does not support scalar bars :(
pv.global_theme.show_scalar_bar = False 

## Initialize a plotter object
plotter = pv.Plotter(window_size=[400,400])

## Create a mesh with a cube 
mesh = pv.Cube(center=(0,0,0))

## Add some scalar field associated to the mesh
mesh['myscalar'] = mesh.points[:, 2]*mesh.points[:, 0]

## Add mesh to the plotter
plotter.add_mesh(mesh, scalars='myscalar', cmap='bwr', line_width=1)

## Final touches
plotter.view_isometric()
plotter.add_scalar_bar()
plotter.background_color = 'white'

## Pass a key to avoid re-rendering at each time something changes in the page
stpyvista(plotter, key="pv_cube")

Also check:

About

🧊 Show pyvista 3D visualizations in streamlit

https://stpyvista.streamlit.app

License:GNU General Public License v3.0


Languages

Language:Python 58.3%Language:JavaScript 33.5%Language:HTML 6.6%Language:CSS 1.7%