# Streamtubes in Plotly with Python

This article is originally published at https://blog.plotly.com/

???? 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 for interactive scientific data visualization, the Mayavi Python library was your go-to.

The charts may have looked slick for their time, but it doesn’t take a rocket scientist to tell you that we’ve come a long way.
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).

• 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 coordindates 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.

Python code | R code | Link to plot | Link to data

## 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!

Python code | R code | Link to plot | Link to data

Onto more complicated examples of streamtubes in Plotly…

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

• 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.

• Why is that important? Chaotic behavior exists in many natural systems and is not limited to turbulence. Other examples include: weather and climate, road traffic, and biology.

• By charting the chaotic behavior, we can gain better insights into it.

• 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:

Python code | Link to plot

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 ????

Python code | Link to plot

## 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.

Python code | Link to plot

## 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.

Python code | Link to plot

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 for her ABC-flow plot contributions.

Thanks for visiting r-craft.org

This article is originally published at https://blog.plotly.com/

Please visit source website for post related comments.