Exporting Plots as Image Files

The render() method allows users to directly plot the curves and surfaces using predefined visualization classes. This method takes some keyword arguments to control plot properties at runtime. Please see the class documentation on description of these keywords. The render() method also allows users to save the plots directly as a file and to control the plot window visibility. The keyword arguments that control these features are filename and plot, respectively.

The following example script illustrates creating a 3-dimensional Bézier curve and saving the plot as bezier-curve3d.pdf without popping up the Matplotlib plot window. filename argument is a string value defining the name of the file to be saved and plot flag controls the visibility of the plot window.

 1from geomdl import BSpline
 2from geomdl import utilities
 3from geomdl.visualization import VisMPL
 4
 5# Create a 3D B-Spline curve instance (Bezier Curve)
 6curve = BSpline.Curve()
 7
 8# Set up the Bezier curve
 9curve.degree = 3
10curve.ctrlpts = [[10, 5, 10], [10, 20, -30], [40, 10, 25], [-10, 5, 0]]
11
12# Auto-generate knot vector
13curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts))
14
15# Set sample size
16curve.sample_size = 40
17
18# Evaluate curve
19curve.evaluate()
20
21# Plot the control point polygon and the evaluated curve
22vis_comp = VisMPL.VisCurve3D()
23curve.vis = vis_comp
24
25# Don't pop up the plot window, instead save it as a PDF file
26curve.render(filename="bezier-curve3d.pdf", plot=False)

This functionality strongly depends on the plotting library used. Please see the documentation of the plotting library that you are using for more details on its figure exporting capabilities.