pyplot

Plotting utility functions.

donut

vtkplotter.pyplot.donut(fractions, title='', 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

  • 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

vtkplotter.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
  • title (str) – histogram title

  • 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

  • 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

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

  • line (bool) – join points with 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 vtkplotter 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

  • 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

  • lw (int) – line width in pixels

  • deg (bool) – input array is in degrees

  • fill (bool) – fill convex area with solid color

  • spline (bool) – interpolate the set of input points

  • showPoints (bool) – show data points

  • showDisc (bool) – show the outer ring axis

  • showLines (bool) – show lines to the origin

  • showAngles (bool) – show angular 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

vtkplotter.pyplot.quiver(points, vectors, cmap='jet', 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

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

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