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
  • c – color of the Graph

  • n (int) – number of the initial set of nodes

  • layout (int,str) – layout in [‘2d’, ‘fast2d’, ‘clustering2d’, ‘circular’, ‘circular3d’, ‘cone’, ‘force’, ‘tree’]

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 sub-trees 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

lineage_graph.py lineage_graph.py

graph_network.py graph_network.py

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.

addEdge(v1, v2, label='')[source]

Add a new edge between to nodes. An extra node is created automatically if needed.

addNode(label='id')[source]

Add a new node to the Graph.

build()[source]

Build the DirectedGraph(Assembly). Accessory objects are also created for labels and arrows.

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

donut.py donut.py

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.

  • logscale (bool) – use logscale on y-axis.

  • 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.

histo_1D.py histo_1D.py

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

histo_polar.py histo_polar.py

For 2D arrays:

Input data formats [(x1,x2,..), (y1,y2,..)] or [(x1,y1), (x2,y2),..] are both valid.

Parameters
  • xtitle (str) – x axis title

  • ytitle (str) – y axis title

  • bins (list) – binning as (nx, ny)

  • vrange (list) – range in x and y in format [(xmin,xmax), (ymin,ymax)]

  • cmap (str) – color map name

  • lw (float) – line width of the binning

  • scalarbar (bool) – add a scalarbar

histo_2D.py histo_2D.py

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.

histo_hexagonal.py histo_hexagonal.py

If mode='spheric', build a histogram from list of theta and phi values.

Parameters
  • rmax (float) – maximum radial elevation of bin

  • res (int) – sphere resolution

  • cmap – color map name

  • lw (float) – line width of the bin edges

  • scalarbar (bool) – add a scalarbar to plot

histo_spheric.py histo_spheric.py

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 x-axis.

  • ytitle (str) – title label along y-axis.

  • 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

  • marker (str,int) – use a marker shape for the data points

  • 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()

simpleplot

More examples:

plot1_errbars.py plot1_errbars.py

plot2_errband.py plot2_errband.py

plot3_pip.py plot3_pip.py

scatter1.py scatter1.py

scatter2.py scatter2.py

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 z-levels contour lines.

  • showNan (bool) – show where the function does not exist as red points.

  • bins (list) – number of bins in x and y.

plot4_fxy.py plot4_fxy.py

Function is: \(f(x,y)=\sin(3x) \cdot \log(x-y)/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
  • cmap (str) – diverging color map (white means imag(z)=0).

  • lw (float) – line with of the binning

  • bins (list) – binning in x and y

fcomplex plot4_fxy.py

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

histo_polar.py histo_polar.py

If mode='spheric' input input is an external function rho(theta, phi). A surface is created in spherical coordinates. Return an Plot(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

plot5_spheric.py plot5_spheric.py

quiver

vedo.pyplot.quiver(points, vectors, c='k', alpha=1, shaftLength=0.8, shaftWidth=0.05, headLength=0.25, headWidth=0.2, fill=True, scale=1)[source]

Quiver Plot, display vectors at points locations.

Color can be specified as a colormap which maps the size of the arrows.

Parameters
  • shaftLength (float) – fractional shaft length

  • shaftWidth (float) – fractional shaft width

  • headLength (float) – fractional head length

  • headWidth (float) – fractional head width

  • fill (bool) – if False only generate the outline

  • scale (float) – apply a rescaling factor to the length

quiver.py quiver.py

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

plot7_stream.py plot7_stream.py

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 histogram.

Parameters
  • bins (int) – number of bins

  • vlim (list) – input value limits. Crop values outside range.

  • x (list) – x-position 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

histo_violin.py histo_violin.py