A python module for scientific visualization, analysis of 3D objects and point clouds.
Main visualization system including the Plotter class for scene management, matplotlib-style pyplot interface, and specialized plotting functions for scientific data visualization. This module provides the core rendering and interaction capabilities that make vedo visualizations possible.
The Plotter class serves as the central rendering engine, managing 3D scenes, cameras, lighting, and user interactions.
class Plotter:
"""
Main class for managing 3D scenes and rendering.
Parameters:
- shape: tuple, default (1, 1)
Grid layout for multiple viewports (rows, cols)
- N: int, optional
Total number of sub-renderers
- pos: tuple, default (0, 0)
Window position on screen
- size: str or tuple, default "auto"
Window size specification
- screensize: str or tuple, default "auto"
Screen size reference
- title: str, default "vedo"
Window title
- bg: str or tuple, default "white"
Background color
- bg2: str or tuple, optional
Second background color for gradient
- axes: int or dict, optional
Axes configuration
"""
def __init__(
self,
shape=(1, 1),
N=None,
pos=(0, 0),
size="auto",
screensize="auto",
title="vedo",
bg="white",
bg2=None,
axes=None
): ...
def add(self, *objs, at=None):
"""
Add objects to the scene.
Parameters:
- *objs: variable arguments
Objects to add to scene
- at: int, optional
Viewport index for multi-viewport layouts
Returns:
Plotter: Self for method chaining
"""
def show(self, *objs, **kwargs):
"""
Render and display the scene.
Parameters:
- *objs: variable arguments
Additional objects to add before showing
- **kwargs: keyword arguments
Additional display options
Returns:
Plotter: Self for method chaining
"""
def close(self):
"""Close the plotter window and clean up resources."""
def remove(self, *objs, at=None):
"""
Remove objects from the scene.
Parameters:
- *objs: variable arguments
Objects to remove from scene
- at: int, optional
Viewport index for multi-viewport layouts
Returns:
Plotter: Self for method chaining
"""
def pop(self, at=None):
"""
Remove and return the last added object.
Parameters:
- at: int, optional
Viewport index
Returns:
vedo object: Last added object
"""
def clear(self, at=None, deep=False):
"""
Clear all objects from scene.
Parameters:
- at: int, optional
Viewport index to clear
- deep: bool, default False
Perform deep cleanup of VTK objects
Returns:
Plotter: Self for method chaining
"""
def render(self, resetcam=False):
"""
Render the scene.
Parameters:
- resetcam: bool, default False
Reset camera to fit all objects
Returns:
Plotter: Self for method chaining
"""
def interactive(self):
"""
Start interactive mode for user interaction.
Returns:
Plotter: Self for method chaining
"""
def background(self, c1=None, c2=None, at=None, mode=0):
"""
Set window background color(s).
Parameters:
- c1: str or tuple, optional
Primary background color
- c2: str or tuple, optional
Secondary color for gradient background
- at: int, optional
Viewport index
- mode: int, default 0
Background mode (0=solid, 1=gradient)
Returns:
Plotter: Self for method chaining or current background
"""
def reset_camera(self, tight=None):
"""
Reset camera to show all objects.
Parameters:
- tight: float, optional
Bounding box expansion factor
Returns:
Plotter: Self for method chaining
"""
def camera(self, pos=None, focal_point=None, viewup=None, distance=None, clipping_range=None):
"""
Get or set camera parameters.
Parameters:
- pos: tuple, optional
Camera position
- focal_point: tuple, optional
Camera focal point
- viewup: tuple, optional
Camera up vector
- distance: float, optional
Camera distance from focal point
- clipping_range: tuple, optional
Near and far clipping distances
Returns:
dict or Plotter: Camera parameters or self for chaining
"""
def fly_to(self, point):
"""
Smoothly move camera to look at a point.
Parameters:
- point: tuple
Target point to fly to
Returns:
Plotter: Self for method chaining
"""
def zoom(self, zoom):
"""
Set camera zoom factor.
Parameters:
- zoom: float
Zoom factor (>1 zooms in, <1 zooms out)
Returns:
Plotter: Self for method chaining
"""
def azimuth(self, angle):
"""
Rotate camera around focal point (horizontal rotation).
Parameters:
- angle: float
Rotation angle in degrees
Returns:
Plotter: Self for method chaining
"""
def elevation(self, angle):
"""
Rotate camera around focal point (vertical rotation).
Parameters:
- angle: float
Elevation angle in degrees
Returns:
Plotter: Self for method chaining
"""
def roll(self, angle):
"""
Roll camera around view direction.
Parameters:
- angle: float
Roll angle in degrees
Returns:
Plotter: Self for method chaining
"""High-level functions for quick visualization without explicit Plotter management.
def show(*objects, **kwargs):
"""
Display objects in a 3D scene.
Parameters:
- *objects: variable arguments
3D objects to display (Mesh, Points, Volume, etc.)
- title: str, optional
Window title
- bg: str or tuple, optional
Background color
- axes: int or dict, optional
Axes display configuration
- camera: dict, optional
Camera position and orientation
- interactive: bool, default True
Enable user interaction
- viewup: tuple, optional
Camera up vector
- zoom: float, optional
Camera zoom factor
- elevation: float, optional
Camera elevation angle
- azimuth: float, optional
Camera azimuth angle
Returns:
Plotter: The plotter instance used for display
"""
def close():
"""Close all open plotter windows."""Event system for interactive applications and custom user interactions.
class Event:
"""
Event information container for user interactions.
Attributes:
- name: str
Event name/type
- title: str
Window title
- id: int
Event identifier
- timerid: int
Timer event identifier
- time: float
Event timestamp
- priority: float
Event priority
- at: int
Viewport index
- object: object
Associated object
- actor: object
VTK actor involved
- picked3d: tuple
3D coordinates of picked point
- keypress: str
Key pressed (for keyboard events)
- picked2d: tuple
2D screen coordinates
"""
def __init__(self): ...Matplotlib-style plotting interface for scientific data visualization and analysis.
def plot(*args, **kwargs):
"""
Create line plots with matplotlib-style interface.
Parameters:
- *args: variable arguments
Data arrays (x, y) or (y,) for plotting
- c: str or tuple, optional
Line color
- lw: float, optional
Line width
- ls: str, optional
Line style ('-', '--', '-.', ':')
- marker: str, optional
Marker style ('o', 's', '^', etc.)
- ms: float, optional
Marker size
- alpha: float, optional
Transparency
- label: str, optional
Label for legend
Returns:
PlotXY: Plot object
"""
def histogram(*args, **kwargs):
"""
Create histogram plots.
Parameters:
- *args: variable arguments
Data array(s) to histogram
- bins: int or array-like, optional
Number of bins or bin edges
- weights: array-like, optional
Weights for data points
- density: bool, default False
Normalize to probability density
- alpha: float, optional
Transparency
- c: str or tuple, optional
Fill color
Returns:
Histogram1D or Histogram2D: Histogram object
"""
def fit(points, deg=1, niter=1000, nstd=3):
"""
Fit polynomial curves to data with confidence intervals.
Parameters:
- points: array-like
Input data points
- deg: int, default 1
Polynomial degree
- niter: int, default 1000
Number of bootstrap iterations
- nstd: float, default 3
Standard deviations for confidence interval
Returns:
dict: Fitting results with curve and confidence bands
"""
def pie_chart(fractions, title="", c=None, bc="white", r1=1.7, r2=1, pos=(0, 0), lw=0.5, alpha=1, labels=None, showValues=False):
"""
Create pie chart visualizations.
Parameters:
- fractions: array-like
Data values for pie segments
- title: str, default ""
Chart title
- c: list or str, optional
Colors for segments
- bc: str, default "white"
Border color
- r1: float, default 1.7
Outer radius
- r2: float, default 1
Inner radius (for donut chart)
- pos: tuple, default (0, 0)
Chart position
- lw: float, default 0.5
Border line width
- alpha: float, default 1
Transparency
- labels: list, optional
Segment labels
- showValues: bool, default False
Show numerical values
Returns:
Assembly: Pie chart assembly
"""
def violin(values, bins=10, fill=True, c="violet", alpha=1, lw=2, pos=(0, 0), s=1):
"""
Create violin plots for data distribution visualization.
Parameters:
- values: array-like
Data values to plot
- bins: int, default 10
Number of histogram bins
- fill: bool, default True
Fill the violin shape
- c: str or tuple, default "violet"
Fill color
- alpha: float, default 1
Transparency
- lw: float, default 2
Line width
- pos: tuple, default (0, 0)
Plot position
- s: float, default 1
Scale factor
Returns:
Mesh: Violin plot mesh
"""
def whisker(data, s=0.25, c="k", lw=2, bc="blue", alpha=0.25, r=5, jitter=True, horizontal=False):
"""
Create box and whisker plots.
Parameters:
- data: array-like
Input data for box plot
- s: float, default 0.25
Box width scale
- c: str or tuple, default "k"
Line color
- lw: float, default 2
Line width
- bc: str or tuple, default "blue"
Box fill color
- alpha: float, default 0.25
Box transparency
- r: float, default 5
Point size for outliers
- jitter: bool, default True
Add horizontal jitter to points
- horizontal: bool, default False
Create horizontal box plot
Returns:
Assembly: Box plot assembly
"""
def streamplot(X, Y, U, V, direction="forward", integrator="rk2", maxPropagation=100, initialStepLength=0.1, lw=2, cmap="viridis", tubes=False):
"""
Create streamline visualizations of vector fields.
Parameters:
- X, Y: array-like
Grid coordinates
- U, V: array-like
Vector field components
- direction: str, default "forward"
Integration direction
- integrator: str, default "rk2"
Integration method
- maxPropagation: float, default 100
Maximum streamline length
- initialStepLength: float, default 0.1
Initial integration step size
- lw: float, default 2
Line width
- cmap: str, default "viridis"
Colormap name
- tubes: bool, default False
Render as tubes instead of lines
Returns:
Mesh: Streamline visualization
"""
def matrix(M, title="Matrix", xtitle="", ytitle="", c="red", bg="white", cmap="Reds", alpha=1, lw=0, pos=(0, 0), s=1):
"""
Visualize matrices as colored grids.
Parameters:
- M: array-like
2D matrix data
- title: str, default "Matrix"
Plot title
- xtitle: str, default ""
X-axis title
- ytitle: str, default ""
Y-axis title
- c: str or tuple, default "red"
Default color
- bg: str or tuple, default "white"
Background color
- cmap: str, default "Reds"
Colormap name
- alpha: float, default 1
Transparency
- lw: float, default 0
Line width for grid
- pos: tuple, default (0, 0)
Plot position
- s: float, default 1
Scale factor
Returns:
Figure: Matrix visualization
"""Specialized plot classes for complex data visualization needs.
class Figure(Assembly):
"""
Base class for all plot figures, extending Assembly functionality.
Parameters:
- xlim: tuple, optional
X-axis limits
- ylim: tuple, optional
Y-axis limits
- aspect: str, default "equal"
Aspect ratio specification
- padding: float, default 0.05
Plot area padding
- xtitle: str, default ""
X-axis title
- ytitle: str, default ""
Y-axis title
- title: str, default ""
Plot title
"""
def __init__(self, xlim=None, ylim=None, aspect="equal", padding=0.05, xtitle="", ytitle="", title=""): ...
class PlotXY(Figure):
"""
2D line plotting class with extensive customization options.
Parameters:
- data: array-like
Data points for plotting
- xerrors: array-like, optional
X error bars
- yerrors: array-like, optional
Y error bars
- lw: float, default 2
Line width
- lc: str or tuple, default "blue"
Line color
- la: float, default 1
Line transparency
- dashed: bool, default False
Use dashed line style
- marker: str, optional
Marker style
- ms: float, optional
Marker size
- mc: str or tuple, optional
Marker color
"""
def __init__(self, data, xerrors=None, yerrors=None, lw=2, lc="blue", la=1, dashed=False, marker=None, ms=None, mc=None): ...
class PlotBars(Figure):
"""
Bar chart plotting class.
Parameters:
- data: array-like
Bar heights or (x, height) pairs
- errors: array-like, optional
Error bar values
- c: str or tuple, default "blue"
Bar color
- alpha: float, default 1
Bar transparency
"""
def __init__(self, data, errors=None, c="blue", alpha=1): ...
class Histogram1D(Figure):
"""
1D histogram visualization class.
Parameters:
- data: array-like
Input data to histogram
- bins: int or array-like, default 25
Number of bins or bin edges
- weights: array-like, optional
Data point weights
- c: str or tuple, default "blue"
Fill color
- alpha: float, default 1
Transparency
- outline: bool, default False
Draw histogram outline
"""
def __init__(self, data, bins=25, weights=None, c="blue", alpha=1, outline=False): ...
class Histogram2D(Figure):
"""
2D histogram/heatmap visualization class.
Parameters:
- xdata: array-like
X-axis data
- ydata: array-like
Y-axis data
- bins: int or tuple, default 25
Number of bins for each axis
- weights: array-like, optional
Data point weights
- cmap: str, default "viridis"
Colormap name
- alpha: float, default 1
Transparency
"""
def __init__(self, xdata, ydata, bins=25, weights=None, cmap="viridis", alpha=1): ...
class DirectedGraph(Assembly):
"""
Directed graph/network visualization class.
Parameters:
- c: str or tuple, default "blue"
Default node/edge color
- alpha: float, default 1
Transparency
"""
def __init__(self, c="blue", alpha=1): ...Specialized plotting functions for analyzing multi-dimensional datasets.
def CornerPlot(points, pos=1, s=0.2, title="", c="b", bg="k", lines=True, dots=True):
"""
Create corner plots for multi-dimensional data analysis.
Parameters:
- points: array-like
Multi-dimensional data points
- pos: int, default 1
Plot position
- s: float, default 0.2
Point size
- title: str, default ""
Plot title
- c: str or tuple, default "b"
Point color
- bg: str or tuple, default "k"
Background color
- lines: bool, default True
Show regression lines
- dots: bool, default True
Show data points
Returns:
Assembly: Corner plot assembly
"""
def CornerHistogram(values, bins=25, vrange=None, diagonal=True, fill=True, c="blue", bg="white", alpha=1, lw=1, pos=(0, 0), s=1):
"""
Create corner histogram plots for multi-dimensional data.
Parameters:
- values: array-like
Multi-dimensional data
- bins: int, default 25
Number of histogram bins
- vrange: tuple, optional
Value range for binning
- diagonal: bool, default True
Show diagonal histograms
- fill: bool, default True
Fill histogram areas
- c: str or tuple, default "blue"
Fill color
- bg: str or tuple, default "white"
Background color
- alpha: float, default 1
Transparency
- lw: float, default 1
Line width
- pos: tuple, default (0, 0)
Plot position
- s: float, default 1
Scale factor
Returns:
Assembly: Corner histogram assembly
"""import vedo
import numpy as np
# Basic scene setup with Plotter
plt = vedo.Plotter(title="Advanced Visualization", bg='lightgray')
# Add 3D objects
sphere = vedo.Sphere(c='red', alpha=0.8)
points = vedo.Points(np.random.rand(1000, 3) * 5, c='blue', r=3)
plt.add(sphere, points)
plt.show()
# Quick visualization with show()
mesh = vedo.load("data.stl")
vedo.show(mesh, axes=True, title="Loaded Mesh")
# Scientific plotting
x = np.linspace(0, 2*np.pi, 100)
y1 = np.sin(x)
y2 = np.cos(x)
# Line plots
plot1 = vedo.plot(x, y1, c='red', lw=3, label='sin(x)')
plot2 = vedo.plot(x, y2, c='blue', lw=3, label='cos(x)')
# Histogram
data = np.random.normal(0, 1, 1000)
hist = vedo.histogram(data, bins=30, c='green', alpha=0.7)
# Advanced plots
fig = vedo.PlotXY([(x, y1), (x, y2)],
lc=['red', 'blue'],
lw=2,
xtitle="Angle (rad)",
ytitle="Amplitude",
title="Trigonometric Functions")
# Multi-dimensional data visualization
data_2d = np.random.multivariate_normal([0, 0], [[1, 0.5], [0.5, 1]], 500)
corner = vedo.CornerPlot(data_2d, c='purple', title="2D Data Distribution")
# Matrix visualization
matrix_data = np.random.rand(10, 10)
mat_plot = vedo.matrix(matrix_data, title="Random Matrix", cmap='plasma')
# Display results
vedo.show([plot1, plot2], at=0, N=2)
vedo.show(hist, at=1)Install with Tessl CLI
npx tessl i tessl/pypi-vedo