# Streamtubes in Plotly with Python and R

Aug 13, 2018 Â· 4 min read

đźŚź Before we introduce this seriously cool visualization, weâ€™d like to announce that plotly.py has surpassed 5 million downloads! Thank you for helping us reach this milestone! đź™Ś

## Once Upon a Time đź•°ď¸Ź

It was the year 2008. If you wanted to create 3-D plots in Python for interactive scientific data visualization, the Mayavi Python library was your go-to.

See for yourself:

Mayavi Streamtube Example, circa 2008

Plotly Streamtube Example, 2018

## So Whatâ€™s a Streamtube?

• A streamtube is a tubular region surrounded by streamlines that form a closed loop.
• Itâ€™s a continuous version of a cone plot (3-D quiver plot) and can provide insight into flow data from natural systems.
• A streamtube is impermeable since the walls of the tube are made up of streamlines, and there can be no flow normal to a streamline.
• Since streamlines donâ€™t intersect, the same streamlines pass through a streamtube at all points along its length.

Streamtubes in Plotly â¤µď¸Ź

https://plot.ly/python/streamtube-plot/

• In streamtube plots, attributes include `x`, `y`, and `z`, which set the coordinates of the vector field, and `u`, `v`, and `w`, which sets the `x`, `y`, and `z` components of the vector field.
• You can use `starts` to determine the streamtube's starting position.
• The maximum number of segments displayed can be determined by calling `maxdisplayed` in your chart code.

## 1. Basic Streamtube

Our first example is a simple one. It satisfies the definition of a streamtube wholly: a tubular region surrounded by streamlines that form a closed loop.

This particular tubular region is made up of 27 streamlines.

## 2. Starting Position and Segments

This plot shows how you can display wind speed and direction as a streamtube. It uses two functions that are unique to this particular chart type: `starts` and `maxdisplayed`, which are described above.

When dealing with wind data, be sure to use a colorscale that highlights the peak values!

On to more complicated examples of streamtubes in Plotlyâ€¦

## 3. Streamtubes Displaying the Arnold-Beltrami-Childress (ABC) Flow

The ABC-flow is an example of dynamic chaos. Since chaotic behavior exists in many natural systems, like weather and climate, road traffic, and biology, we can gain better insights by charting it.

• The ABC-flow is a three-parameter incompressible velocity field that provides an exact solution of Eulerâ€™s equation for inviscid Newtonian fluids in three dimensions.
• Eulerâ€™s equation is a special case of the Navier-Stokes equation, which expresses Newtonâ€™s 2nd law of motion for fluid flow. Newtonâ€™s 2nd law of motion states that the sum of the forces acting on the volume of fluid V is equal to the rate of change of its momentum.
• Inviscid flow is the flow of an inviscid fluid, in which the viscosity, or thickness, of the fluid is equal to zero.
• It is the prototype for the study of turbulence, providing a simple example of dynamic chaos.
• In Cartesian coordinates, it is represented as:

x = A sin z + C cos y

y = B sin x + A cos z

z = C sin y + B cos x

The cone plot representation of the ABC-vector field defined on a volumetric region:

The second example below shows streamtubes displaying the ABC-flow starting from a z-plane. The ABC-vectors have a fast change of the direction and magnitude in each slice perpendicular to one of the axes. In this case, we gain better insights into the flow structure, plotting the streamtubes that start from different volume slices.

We think it looks like a cool haircut đź’‡

## Streamtubes of the ABC-Flow: Flowing from X-Plane

Here we illustrate streamtubes of the ABC-flow that start from a plane perpendicular to the x-axis.

The previous example showed streamtubes that are flowing from a plane perpendicular to the z-axis.

## Streamtubes of the ABC-Flow: Flowing from Y-Plane

This plot shows streamtubes of the ABC-flow that start from a plane perpendicular to the y-axis.

The previous example showed streamtubes that are flowing from a plane perpendicular to the x-axis.

Although streamtubes represent a plot type that borders on the esoteric, some intriguing applications can be made with a bit of thought and creativity. For inspiration, check out the Plotly feed.

Special thanks to Emilia Petrisor (Emilia P) for her ABC-flow plot contributions.

Written by

## More From Medium

Feb 20, 2018 Â· 8 min read

### 15 Python Libraries That A Data Scientist Need To Know

Mar 29 Â· 10 min read