Skip to content

Saving curves and surfaces from the command line

Onur Rauf Bingol edited this page Jun 29, 2018 · 3 revisions

NURBS-Python (geomdl) v4.0 comes with a nice feature which allows users to save curves and surfaces without opening the figure window. Just to note, export capabilities vary between the visualization modules due to their dependencies. For isntance, VisMPL uses Matplotlib and it can export the plot as an image file (or as a PDF file) directly, whereas VisPlotly uses Plotly for Python and it generates a HTML file which allows you to download the image after opening the HTML file.

In order to test this feature, I used the following software:

  • CentOS v7.5.1804 minimal installation (no X Window System)
  • Python v2.7.5
  • Matplotlib 1.2.0 installed via yum install python-matplotlib

Setting up Matplotlib for windowless operation

In simple words, I followed this StackOverflow answer: https://stackoverflow.com/a/4935945

  • Create .matplotlib directory in your home directory
  • Create matplotlibrc file in matplotlib directory
  • Add backend: Agg inside matplotlibrc file

or alternatively, you may type the following:

cd; mkdir .matplotlib; echo "backend: Agg" >> .matplotlib/matplotlibrc

Script to test

There are a bunch of examples on the Examples Repository but the only necessary change is updating the keyword arguments of the render() method (docs for Curve class, docs for Surface class)

Assuming that you have successfully generated your curve/surface object and the instance is stored in the variable mynurbs. To save the plots, you may update your render() call like this:

mynurbs.render(filename="file_name_to_save.png", plot=False)

You can configure the resolution and other settings using VisConfig class (documentation).