# Visualization of 3D vector fields

In the past few weeks, I spent a lot of time learning how to visualize a 3D vector field interactively. As mentioned in previous posts, my project is aiming to reconstruct the solar magnetic field according to boundary conditions, which are usually the observed image from satellites.

Therefore, how to visualize the 3D extrapolation of the solar magnetic field would be key to the project. Fortunately, there is a python package named *Mayavi*, which provides an easy and interactive visualization of 3D vector data.

To visualize a 3D vector field is more or less similar to plot a 2D figure. You have to define the grid of the figure (it is possible to mask some grid points), and then the vector (direction and magnitude) at each grid point. A few examples are as follows:

- The first example is a vector field on the surface of a sphere. The radius of the sphere is 1. The grid points are 11 × 11 along with
**\phi**and**\theta**directions. At each grid point, the direction of the vector is along the direction of**r**and the magnitude of the vector is 1.

- The second example is a random vector field with uniform distribution. The cube size is 1 × 1 × 1, and the grid points are 5 × 5 × 5 along x, y, and z direction. At each grid point, the x, y, and z components of the vector are uniformly distributed between [-1.0, 1.0).

Having done some simple tests, I am confident to visualize the extrapolated solar magnetic field via Mayavi. In the next few weeks, I am going to focus on the renovation of magnetic field extrapolator. Hope I could show some nice figures after it!