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 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
-
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
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
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
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 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.
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
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¶
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) – 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
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 1-dimensional 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