<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/streamtubes-in-plotly-with-python/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://plotlyblog.tumblr.com/post/178123311802"> Plotly Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img alt="🌟" src="https://s.w.org/images/core/emoji/2.4/72x72/1f31f.png" class="wp-smiley"> 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! <img alt="🙌" src="https://s.w.org/images/core/emoji/2.4/72x72/1f64c.png" class="wp-smiley"></p>
<p>Once Upon a Time <img alt="🕰" src="https://s.w.org/images/core/emoji/2.4/72x72/1f570.png" class="wp-smiley"></p>
<p>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.</p>
<p>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.<br>
See for yourself:</p>
<h2>Mayavi Streamtube Example, circa 2008</h2>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/MDPKZOL.png" data-orig-height="696"><img data-orig-width="450" data-orig-src="https://i.imgur.com/MDPKZOL.png" src="https://i1.wp.com/78.media.tumblr.com/7e882d5d079504fec2055b97a053517f/tumblr_inline_pf4dawQWT01srua81_540.png?resize=450%2C696&ssl=1" data-recalc-dims="1" data-orig-height="696"></figure>
<h2>Plotly Streamtube Example, 2018</h2>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/BgxJzkx.png" data-orig-height="622"><img data-orig-width="450" data-orig-src="https://i.imgur.com/BgxJzkx.png" src="https://i1.wp.com/78.media.tumblr.com/4aac1fb53f7e8c43f1b23d57e98a17e4/tumblr_inline_pf4dawzpx11srua81_540.png?resize=450%2C622&ssl=1" data-recalc-dims="1" data-orig-height="622"></figure>
<p></p>
<h2>So What’s a Streamtube?</h2>
<p>• A streamtube is a tubular region surrounded by streamlines that form a closed loop.</p>
<p>• It’s a continuous version of a cone plot (3-D quiver plot).</p>
<p>• 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.</p>
<p>• Since streamlines don’t intersect, the same streamlines pass through a streamtube at all points along its length.</p>
<h2>Streamtubes in Plotly <img alt="⤵" src="https://s.w.org/images/core/emoji/2.4/72x72/2935.png" class="wp-smiley"></h2>
<p>
<a rel="nofollow" href="https://plot.ly/python/streamtube-plot/" target="_blank">https://plot.ly/python/streamtube-plot/</a></p>
<p>• In streamtube plots, attributes include <i>x</i>, <i>y</i>, and <i>z</i>, which set the coordindates of the vector field, and <i>u</i>, <i>v</i>, and <i>w</i>, which sets the <i>x</i>, <i>y</i>, and <i>z</i> components of the vector field.</p>
<p>• You can use <i>starts</i> to determine the streamtube’s starting position.</p>
<p>• The maximum number of segments displayed can be determined by calling <i>maxdisplayed</i> in your chart code.</p>
<h2>1. Basic Streamtube</h2>
<p>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.</p>
<p>This particular tubular region is made up of 27 streamlines.</p>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/7szxr0N.gif" data-orig-height="594"><img data-orig-width="450" data-orig-src="https://i.imgur.com/7szxr0N.gif" src="https://i2.wp.com/78.media.tumblr.com/f3f3c65cc1a389bbaa8d97b151391042/tumblr_inline_pf4daxIBlg1srua81_540.gif?resize=450%2C594&ssl=1" data-recalc-dims="1" data-orig-height="594"></figure>
<p><a rel="nofollow" href="https://plot.ly/~Dreamshot/9281/import-plotly-plotly-version-/#/" target="_blank">Python code</a> | <a rel="nofollow" href="https://plot.ly/r/streamtube-plot/" target="_blank">R code</a> | <a rel="nofollow" href="https://plot.ly/~Dreamshot/9279/#/" target="_blank">Link to plot</a> | <a rel="nofollow" href="https://raw.githubusercontent.com/plotly/datasets/master/streamtube-basic.csv" target="_blank">Link to data</a></p>
<h2>2. Starting Position and Segments</h2>
<p>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: <i>starts</i> and <i>maxdisplayed</i>, which are described above.</p>
<p>When dealing with wind data, be sure to use a colorscale that highlights the peak values!</p>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/J3KZljc.gif" data-orig-height="733"><img data-orig-width="450" data-orig-src="https://i.imgur.com/J3KZljc.gif" src="https://i1.wp.com/78.media.tumblr.com/e82efc8a50d5b61d6b0b85f5b01032aa/tumblr_inline_pf4daxJcwz1srua81_540.gif?resize=450%2C733&ssl=1" data-recalc-dims="1" data-orig-height="733"></figure>
<p><a rel="nofollow" href="https://plot.ly/~Dreamshot/9284/import-plotly-plotly-version-/#/" target="_blank">Python code</a> | <a rel="nofollow" href="https://plot.ly/r/streamtube-plot/" target="_blank">R code</a> | <a rel="nofollow" href="https://plot.ly/~Dreamshot/9282/#/" target="_blank">Link to plot</a> | <a rel="nofollow" href="https://raw.githubusercontent.com/plotly/datasets/master/streamtube-wind.csv" target="_blank">Link to data</a></p>
<p>Onto more complicated <a rel="nofollow" href="https://plot.ly/~empet/14972/vector-field-visualization-with/#/" target="_blank">examples</a> of streamtubes in Plotly…</p>
<h2>3. Streamtubes Displaying the Arnold-Beltrami-Childress (ABC) Flow</h2>
<p>• The <a rel="nofollow" href="https://arxiv.org/ftp/arxiv/papers/1512/1512.04367.pdf" target="_blank">ABC flow</a> is a three-parameter incompressible velocity field that provides an exact solution of Euler’s equation for inviscid Newtonian fluids in three dimensions.</p>
<p>• 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.</p>
<p>• Inviscid flow is the flow of an inviscid fluid, in which the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Viscosity" target="_blank">viscosity</a>, or thickness, of the fluid is equal to zero.</p>
<p>• It is the prototype for the study of turbulence, providing a simple example of dynamic chaos.</p>
<p>• 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.</p>
<p>• By charting the chaotic behavior, we can gain better insights into it.</p>
<p>• In Cartesian coordinates, it is represented as:</p>
<p><i>x = A sin z + C cos y</i><br>
<br><i>y = B sin x + A cos z</i><br>
<br><i>z = C sin y + B cos x</i></p>
<p>The cone plot representation of the ABC-vector field defined on a volumetric region:</p>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/SzawQqu.gif" data-orig-height="600"><img data-orig-width="450" data-orig-src="https://i.imgur.com/SzawQqu.gif" src="https://i1.wp.com/78.media.tumblr.com/4d36c10b6615fd10f967a94da7ec2aab/tumblr_inline_pf4daxazq21srua81_540.gif?resize=450%2C600&ssl=1" data-recalc-dims="1" data-orig-height="600"></figure>
<p><a rel="nofollow" href="https://plot.ly/~empet/14971/vector-field-visualization-wit/#/" target="_blank">Python code</a> | <a rel="nofollow" href="https://plot.ly/~empet/14950/the-cone-plot-of-the-abc-flow/#/" target="_blank">Link to plot</a></p>
<p>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.</p>
<p>We think it looks like a cool haircut <img alt="💇" src="https://s.w.org/images/core/emoji/2.4/72x72/1f487.png" class="wp-smiley"></p>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/NkvDEUJ.gif" data-orig-height="600"><img data-orig-width="450" data-orig-src="https://i.imgur.com/NkvDEUJ.gif" src="https://i0.wp.com/78.media.tumblr.com/f449dfd167c67ca5c3dff6eb25c4ddee/tumblr_inline_pf4dayH7bg1srua81_540.gif?resize=450%2C600&ssl=1" data-recalc-dims="1" data-orig-height="600"></figure>
<p><a rel="nofollow" href="https://plot.ly/~empet/14972/vector-field-visualization-with/#/" target="_blank">Python code</a> | <a rel="nofollow" href="https://plot.ly/~empet/14961/streamtubes-in-the-abc-flow/#/" target="_blank">Link to plot</a></p>
<h2>Streamtubes of the ABC Flow: Flowing from X-Plane</h2>
<p>Here we illustrate streamtubes of the ABC flow that start from a plane perpendicular to the x-axis.</p>
<p>The previous example showed streamtubes that are flowing from a plane perpendicular to the z-axis.</p>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/EjGmHlK.gif" data-orig-height="600"><img data-orig-width="450" data-orig-src="https://i.imgur.com/EjGmHlK.gif" src="https://i1.wp.com/78.media.tumblr.com/1bdaad4e77d18262fcef0908000308cf/tumblr_inline_pf4dayw1w11srua81_540.gif?resize=450%2C600&ssl=1" data-recalc-dims="1" data-orig-height="600"></figure>
<p><a rel="nofollow" href="https://plot.ly/~empet/14973/vector-field-visualization-with/#/" target="_blank">Python code</a> | <a rel="nofollow" href="https://plot.ly/~empet/14954/streamtubes-in-the-abc-flow/#/" target="_blank">Link to plot</a></p>
<h2>Streamtubes of the ABC Flow: Flowing from Y-Plane</h2>
<p>This plot shows streamtubes of the ABC flow that start from a plane perpendicular to the y-axis.</p>
<p>The previous example showed streamtubes that are flowing from a plane perpendicular to the x-axis.</p>
<figure data-orig-width="450" data-orig-src="https://i.imgur.com/DShB2Oc.gif" data-orig-height="600"><img data-orig-width="450" data-orig-src="https://i.imgur.com/DShB2Oc.gif" src="https://i2.wp.com/78.media.tumblr.com/314ed431e1fcc4fe06057bffeab309a4/tumblr_inline_pf4dayv16n1srua81_540.gif?resize=450%2C600&ssl=1" data-recalc-dims="1" data-orig-height="600"></figure>
<p><a rel="nofollow" href="https://plot.ly/~empet/14974/vector-field-visualization-with/#/" target="_blank">Python code</a> | <a rel="nofollow" href="https://plot.ly/~empet/14952/streamtubes-in-the-abc-flow/#/" target="_blank">Link to plot</a></p>
<p>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 <a rel="nofollow" href="https://plot.ly/feed/?q=streamtubes" target="_blank">Plotly feed</a>.</p>
<p>Special thanks to <a rel="nofollow" href="https://plot.ly/~empet#/" target="_blank">Emilia Petrisor</a> for her ABC-flow plot contributions.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://plotlyblog.tumblr.com/post/178123311802"> Plotly Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/gaMYDStXiYI" height="1"></a></div>