How to | Plot a Vector Field

You can visualize a vector field by plotting vectors on a regular grid, by plotting a selection of streamlines, or by using a gradient color scheme to illustrate vector and streamline densities. You can also plot a vector field from a list of vectors as opposed to a mapping.

Use VectorPlot to plot vectors in a vector field given by a mapping from to :

In[1]:=
Click for copyable input
Out[1]=

Use StreamPlot to plot streamlines:

In[2]:=
Click for copyable input
Out[2]=

Use the StreamPoints option to plot selected streamlines:

In[3]:=
Click for copyable input
Out[3]=

Use the StreamPoints option to select streamlines in the plot:

In[4]:=
Click for copyable input
Out[4]=

Use VectorDensityPlot and StreamDensityPlot to visualize the field densities:

In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=

Use VectorPlot3D to plot a three-dimensional vector field (vectors are colored depending on their magnitude):

In[7]:=
Click for copyable input
Out[7]=
    

In addition to simply plotting vector fields, Mathematica allows you to fine-tune these plots. These examples illustrate some of the options that can be applied.

Use VectorStyle to change the type of arrows in VectorPlot:

In[8]:=
Click for copyable input
Out[8]=

Use StreamPoints to control the number of streamlines in the plot:

In[9]:=
Click for copyable input
Out[9]=

Combine vectors and streamlines into a single plot:

In[10]:=
Click for copyable input
Out[10]=

Use ColorFunction to apply a color scheme based on the density of vectors and streamlines:

In[11]:=
Click for copyable input
Out[11]=

You can use VectorColorFunction to choose a color scheme and specify a function with which to color the vectors. This makes two plots colored with the "DarkRainbow" color scheme, each according to the functions specified in VectorColorFunction:

In[12]:=
Click for copyable input
Out[12]=

Because some functions used in VectorColorFunction are common, Mathematica allows you to call them as variables. These are represented by integers ranging from 1 to 5, where 1 is the variable, 2 is the variable, 3 is the first field component, 4 is the second field component, and 5 is the vector magnitude. To specify these variables, use with VectorColorFunction, where represents the variable number.

Color the plot according to the second field component (), with the "DarkRainbow" color scheme:

In[13]:=
Click for copyable input
Out[13]=

Color the plot according to the vector magnitude (), also with the "DarkRainbow" color scheme:

In[14]:=
Click for copyable input
Out[14]=

Plot streamlines from a specified point, in one direction:

In[15]:=
Click for copyable input
Out[15]=

Use VectorStyle to get 3D effects in VectorPlot3D:

In[16]:=
Click for copyable input
Out[16]=
New to Mathematica? Find your learning path »
Have a question? Ask support »