pyplot¶
Plotting utility functions.
DirectedGraph¶

class
vedo.pyplot.
DirectedGraph
(**kargs)[source]¶ Bases:
vedo.assembly.Assembly
A graph consists of a collection of nodes (without postional information) and a collection of edges connecting pairs of nodes. The task is to determine the node positions only based on their connections.
This class is derived from class
Assembly
, and it assembles 4 Mesh objects representing the graph, the node labels, edge labels and edge arrows. Parameters
Each of these layouts has diferent available options.
Options for layouts ‘2d’, ‘fast2d’ and ‘clustering2d’:
 param int seed
seed of the random number generator used to jitter point positions
 param float restDistance
manually set the resting distance
 param int maxNumberOfIterations
the maximum number of iterations to be used
 param float zrange
expand 2d graph along z axis.
Options for layouts ‘circular’, and ‘circular3d’:
 param float radius
set the radius of the circles.
 param float height
set the vertical (local z) distance between the circles
 param float zrange
expand 2d graph along z axis.
Options for layout ‘cone’:
 param float compactness
ratio between the average width of a cone in the tree, and the height of the cone. The default setting is 0.75.
 param bool compression
put children closer together, possibly allowing subtrees to overlap. This is useful if the tree is actually the spanning tree of a graph.
 param float spacing
space between layers of the tree
Options for layout ‘force’:
 param int seed
seed the random number generator used to jitter point positions
 param list bounds
set the region in space in which to place the final graph
 param int maxNumberOfIterations
the maximum number of iterations to be used
 param bool threeDimensional
allow optimization in the 3rd dimension too
 param bool randomInitialPoints
use random positions within the graph bounds as initial points
Example

addChild
(v, nodeLabel='id', edgeLabel='')[source]¶ Add a new edge to a new node as its child. The extra node is created automatically if needed.
donut¶

vedo.pyplot.
donut
(fractions, title='', tsize=0.3, r1=1.7, r2=1, phigap=0, lpos=0.8, lsize=0.15, c=None, bc='k', alpha=1, labels=(), showDisc=False)[source]¶ Donut plot or pie chart.
 Parameters
title (str) – plot title
tsize (float) – title size
r1 (float) – inner radius
r2 (float) – outer radius, starting from r1
phigap (float) – gap angle btw 2 radial bars, in degrees
lpos (float) – label gap factor along radius
lsize (float) – label size
c – color of the plot slices
bc – color of the disc frame
alpha – alpha of the disc frame
labels (list) – list of labels
showDisc (bool) – show the outer ring axis
histogram¶

vedo.pyplot.
histogram
(*args, **kwargs)[source]¶ Histogramming for 1D and 2D data arrays.
For 1D arrays:
 Parameters
bins (int) – number of bins.
vrange (list) – restrict the range of the histogram.
density (bool) – normalize the area to 1 by dividing by the nr of entries and bin size.
logscale (bool) – use logscale on yaxis.
fill (bool) – fill bars woth solid color c.
gap (float) – leave a small space btw bars.
outline (bool) – show outline of the bins.
errors (bool) – show error bars.
If
mode='polar'
assume input is polar coordinate system (rho, theta): Parameters
weights (list) – array of weights, of the same shape as the input. Each value only contributes its associated weight towards the bin count (instead of 1).
title (str) – histogram title
tsize (float) – title size
bins (int) – number of bins in phi
r1 (float) – inner radius
r2 (float) – outer radius
phigap (float) – gap angle btw 2 radial bars, in degrees
rgap (float) – gap factor along radius of numeric angle labels
lpos (float) – label gap factor along radius
lsize (float) – label size
c – color of the histogram bars, can be a list of length bins.
bc – color of the frame and labels
alpha – alpha of the frame
cmap (str) – color map name
deg (bool) – input array is in degrees
vmin (float) – minimum value of the radial axis
vmax (float) – maximum value of the radial axis
labels (list) – list of labels, must be of length bins
showDisc (bool) – show the outer ring axis
nrays (int) – draw this number of axis rays (continuous and dashed)
showLines (bool) – show lines to the origin
showAngles (bool) – show angular values
showErrors (bool) – show error bars
For 2D arrays:
Input data formats [(x1,x2,..), (y1,y2,..)] or [(x1,y1), (x2,y2),..] are both valid.
 Parameters
If
mode='hexbin'
, build a hexagonal histogram from a list of x and y values. Parameters
xtitle (str) – x axis title
ytitle (str) – y axis title
bins (bool) – nr of bins for the smaller range in x or y.
vrange (list) – range in x and y in format [(xmin,xmax), (ymin,ymax)]
norm (float) – sets a scaling factor for the z axis (freq. axis).
fill (bool) – draw solid hexagons.
cmap (str) – color map name for elevation.
If
mode='spheric'
, build a histogram from list of theta and phi values. Parameters
matrix¶

vedo.pyplot.
matrix
(M, title='Matrix', xtitle='', ytitle='', xlabels=[], ylabels=[], xrotation=0, cmap='Reds', vmin=None, vmax=None, precision=2, font='Theemim', scale=0, scalarbar=True, lc='white', lw=0, c='black', alpha=1)[source]¶ Generate a matrix, or a 2D colorcoded plot with bin labels.
Returns an
Assembly
object. Parameters
M (list or numpy array) – the input array to visualize.
title (str, optional) – title of the plot. The default is ‘Matrix’.
xtitle (str, optional) – title of the horizontal colmuns. The default is ‘’.
ytitle (str, optional) – title of the vertical rows. The default is ‘’.
xlabels (list, optional) – individual string labels for each column. Must be of length m. The default is [].
ylabels (list, optional) – individual string labels for each row. Must be of length n. The default is [].
xrotation (float, optional) – rotation of the horizontal labels. The default is 0.
cmap (str, optional) – color map name. The default is ‘Reds’.
vmin (float, optional) – minimum value of the colormap range. The default is None.
vmax (float, optional) – maximum value of the colormap range. The default is None.
precision (int, optional) – number of digits for the matrix entries or bins. The default is 2.
font (str, optional) – font name. The default is ‘’.
scale (float, optional) – size of the numeric entries or bin values. The default is 0.
scalarbar (bool, optional) – add a scalar bar to the right of the plot. The default is True.
lc (str, optional) – color of the line separating the bins. The default is ‘white’.
lw (float, optional) – Width of the line separating the bins. The default is 0.
c (str, optional) – text color. The default is ‘k’.
alpha (float, optional) – plot transparency. The default is 1.
plot¶

vedo.pyplot.
plot
(*args, **kwargs)[source]¶ Draw a 2D line plot, or scatter plot, of variable x vs variable y. Input format can be either [allx], [allx, ally] or [(x1,y1), (x2,y2), …]
 Parameters
xerrors (list) – set uncertainties for the x variable, shown as error bars.
yerrors (list) – set uncertainties for the y variable, shown as error bars.
errorBand (bool) – represent errors on y as a filled error band. Use
ec
keyword to modify its color.xlim (list) – set limits to the range for the x variable
ylim (list) – set limits to the range for the y variable
aspect (float,) – desired aspect ratio. If None, it is automatically calculated to get a reasonable aspect ratio. Scaling factor is saved in
Plot.yscale
.c (str) – color of frame and text.
alpha (float) – opacity of frame and text.
xtitle (str) – title label along xaxis.
ytitle (str) – title label along yaxis.
title (str) – histogram title on top.
titleSize (float) – size of title
ec (str) – color of error bar, by default the same as marker color
lc (str) – color of line
la (float) – transparency of line
lw (float) – width of line
dashed (bool) – use a dashed line style
splined (bool) – spline the line joining the point as a countinous curve
ms (float) – marker size.
mc (str) – color of marker
ma (float) – opacity of marker
 Example
from vedo import plot import numpy as np x = np.linspace(0, 6.28, num=50) plot(np.sin(x), 'r').plot(np.cos(x), 'bo').show()
More examples:
If input is an external function or a forumula, draw the surface representing the function \(f(x,y)\).
 Parameters
x (float) – x range of values.
y (float) – y range of values.
zlimits (float) – limit the z range of the independent variable.
zlevels (int) – will draw the specified number of zlevels contour lines.
showNan (bool) – show where the function does not exist as red points.
bins (list) – number of bins in x and y.
Function is: \(f(x,y)=\sin(3x) \cdot \log(xy)/3\) in range \(x=[0,3], y=[0,3]\).
If
mode='complex'
draw the real value of the function and color map the imaginary part. Parameters
If
mode='polar'
input arrays are interpreted as a list of polar angles and radii. Build a polar (radar) plot by joining the set of points in polar coordinates. Parameters
title (str) – plot title
tsize (float) – title size
bins (int) – number of bins in phi
r1 (float) – inner radius
r2 (float) – outer radius
lsize (float) – label size
c – color of the line
bc – color of the frame and labels
alpha – alpha of the frame
ps (int) – point size in pixels, if ps=0 no point is drawn
lw (int) – line width in pixels, if lw=0 no line is drawn
deg (bool) – input array is in degrees
vmax (float) – normalize radius to this maximum value
fill (bool) – fill convex area with solid color
spline (bool) – interpolate the set of input points
showDisc (bool) – draw the outer ring axis
nrays (int) – draw this number of axis rays (continuous and dashed)
showLines (bool) – draw lines to the origin
showAngles (bool) – draw angle values
If
mode='spheric'
input input is an external function rho(theta, phi). A surface is created in spherical coordinates. Return anPlot(Assembly)
of 2 objects, the unit grid sphere (in wireframe representation) and the surface rho(theta, phi). Parameters
rfunc (function) – handle to a user defined function.
normalize (bool) – scale surface to fit inside the unit sphere
res (int) – grid resolution
scalarbar (bool) – add a 3D scalarbar to the plot for radius
c – color of the unit grid
alpha – transparency of the unit grid
cmap (str) – color map of the surface
quiver¶
show¶

vedo.pyplot.
show
(*actors, at=None, shape=(1, 1), N=None, pos=(0, 0), size='auto', screensize='auto', title='vedo', bg='white', bg2=None, axes=None, interactive=None, offscreen=False, sharecam=True, resetcam=True, zoom=None, viewup='', azimuth=0, elevation=0, roll=0, camera=None, interactorStyle=0, q=False, new=False)[source]¶ Create on the fly an instance of class
Plotter
and show the object(s) provided.Allowed input objects types are:
str
,Mesh
,Volume
,Picture
,Assembly
vtkPolyData
,vtkActor
,vtkActor2D
,vtkImageActor
,vtkAssembly
orvtkVolume
.If filename is given, its type is guessed based on its extension. Supported formats are: vtu, vts, vtp, ply, obj, stl, 3ds, xml, neutral, gmsh, pcd, xyz, txt, byu, tif, slc, vti, mhd, png, jpg.
 Parameters
at (int) – number of the renderer to plot to, if more than one exists
shape (list) –
Number of subrender windows inside of the main window. Specify two across with
shape=(2, 1)
and a two by two grid withshape=(2, 2)
. By default there is only one renderer. Can also accept a shape as string descriptor. E.g.:shape=”31” means 3 plots on the left and 1 on the right,
shape=”4/2” means 4 plots on top of 2 at bottom.
axes (int) –
set the type of axes to be shown
0, no axes
1, draw three gray grid walls
2, show cartesian axes from (0,0,0)
3, show positive range of cartesian axes from (0,0,0)
4, show a triad at bottom left
5, show a cube at bottom left
6, mark the corners of the bounding box
7, draw a 3D ruler at each side of the cartesian axes
8, show the
vtkCubeAxesActor
object9, show the bounding box outLine
10, show three circles representing the maximum bounding box
11, show a large grid on the xy plane
12, show polar axes
13, draw a simple ruler at the bottom of the window
Axis type1 can be fully customized by passing a dictionary
axes=dict()
where: Checkaddons.Axes()
for the full list of options.azimuth/elevation/roll (float) – move camera accordingly
viewup (str) – either [‘x’, ‘y’, ‘z’] or a vector to set vertical direction
resetcam (bool) – readjust camera position to fit objects
camera (dict) –
Camera parameters can further be specified with a dictionary assigned to the
camera
keyword (E.g. show(camera={‘pos’:(1,2,3), ‘thickness’:1000,}))pos, (list), the position of the camera in world coordinates
focalPoint (list), the focal point of the camera in world coordinates
viewup (list), the view up direction for the camera
distance (float), set the focal point to the specified distance from the camera position.
 clippingRange (float), distance of the near and far clipping planes along the direction
of projection.
 parallelScale (float),
scaling used for a parallel projection, i.e. the height of the viewport in worldcoordinate distances. The default is 1. Note that the “scale” parameter works as an “inverse scale”, larger numbers produce smaller images. This method has no effect in perspective projection mode.
 thickness (float),
set the distance between clipping planes. This method adjusts the far clipping plane to be set a distance ‘thickness’ beyond the near clipping plane.
 viewAngle (float),
the camera view angle, which is the angular height of the camera view measured in degrees. The default angle is 30 degrees. This method has no effect in parallel projection mode. The formula for setting the angle up for perfect perspective viewing is: angle = 2*atan((h/2)/d) where h is the height of the RenderWindow (measured by holding a ruler up to your screen) and d is the distance from your eyes to the screen.
interactive (bool) – pause and interact with window (True) or continue execution (False)
rate (float) – maximum rate of show() in Hertz
interactorStyle (int) –
set the type of interaction
0 = TrackballCamera [default]
1 = TrackballActor
2 = JoystickCamera
3 = JoystickActor
4 = Flight
5 = RubberBand2D
6 = RubberBand3D
7 = RubberBandZoom
8 = Context
9 = 3D
10 = Terrain
11 = Unicam
q (bool) – force program to quit after show() command returns.
new (bool) – if set to True, a call to
show
will instantiate a newPlotter
object (a new window) instead of reusing the first created.
 Returns
the current
Plotter
class instance.
Note
With multiple renderers, keyword
at
can become a list, e.g.from vedo import * s = Sphere() c = Cube() p = Paraboloid() show(s, c, at=[0, 1], shape=(3,1)) show(p, at=2, interactive=True) # # is equivalent to: plt = Plotter(shape=(3,1)) s = Sphere() c = Cube() p = Paraboloid() plt.show(s, at=0) plt.show(p, at=1) plt.show(c, at=2, interactive=True)
streamplot¶

vedo.pyplot.
streamplot
(X, Y, U, V, direction='both', maxPropagation=None, mode=1, lw=0.001, c=None, probes=())[source]¶ Generate a streamline plot of a vectorial field (U,V) defined at positions (X,Y). Returns a
Mesh
object. Parameters
direction (str) – either “forward”, “backward” or “both”
maxPropagation (float) – maximum physical length of the streamline
lw (float) – line width in absolute units
mode (int) –
vary line width
0  do not vary line width
1  vary line width by first vector component
2  vary line width vector magnitude
3  vary line width by absolute value of first vector component
violin¶

vedo.pyplot.
violin
(values, bins=10, vlim=None, x=0, width=3, spline=True, fill=True, c='violet', alpha=1, outline=True, centerline=True, lc='darkorchid', lw=3)[source]¶ Violin style histogram.
 Parameters
bins (int) – number of bins
vlim (list) – input value limits. Crop values outside range.
x (list) – xposition of the violin axis
width (float) – width factor of the normalized distribution
spline (bool) – spline points
fill (bool) – fill violin with solid color
outline (bool) – add the distribution outline
centerline (bool) – add the vertical centerline at x
lc – line color
whisker¶

vedo.pyplot.
whisker
(data, s=0.25, c='k', lw=2, bc='blue', alpha=0.25, r=5, jitter=True, horizontal=False)[source]¶ Generate a “whisker” bar from a 1dimensional dataset.
 Parameters
s (float) – size of the box
c – color of the lines
lw (float) – line width
bc – color of the box
alpha (float) – transparency of the box
r (float) – point radius in pixels (use value 0 to disable)
jitter (bool) – add some randomness to points to avoid overlap
horizontal (bool) – set horizontal layout