Showing posts with label 3D. Show all posts
Showing posts with label 3D. Show all posts

Sunday, February 14, 2021

Generating 3D Plots and Exporting the Geometry - An Example with Antenna Radiation in Matplotlib, PyVista and Blender

This was made starting from a Python script using Matplotlib. This post shows how. 

Discussion

Matplotlib is a great tool for generating beautiful 2D and 3D images quickly. 


However, sometimes its desirable to generate something more visual and appealing to help explain a concept more clearly. Often this is not possible in Matplotlib. Other tools must be used.  However, there is not facility in Matplotlib (as of 3.2.1) to export that plot surface for use in other tools. 
Fortunately, using almost the same syntax as Matplotlib, a 3D plot can be created in PyVista and exported in one of the common 3D file formation like stl, ply, or fbx. Once this is done, its possible to import into a tool like Blender and create a high quality rendering or animation to help explain a concept. 

This posting will cover the key steps in doing this and use the plotting of the radiation pattern of an antenna to help illustrate.


Setup

You'll need Python 3 with Matplotlib, PyVista, and Blender to replicate this. My personal setup uses the portable version of Python 3 and Blender.
  1. Install WinPython portable (https://winpython.github.io/)
  2. Use pypi to install PyVista (https://pypi.org/project/pyvista/)
  3. Install Blender portable (https://www.blender.org/download/ and chose the portable version)

Example