Skip to content

Latest commit

 

History

History
112 lines (90 loc) · 3.07 KB

streamline-plots.md

File metadata and controls

112 lines (90 loc) · 3.07 KB
jupyter
jupytext kernelspec language_info plotly
notebook_metadata_filter text_representation
all
extension format_name format_version jupytext_version
.md
markdown
1.1
1.1.1
display_name language name
Python 3
python
python3
codemirror_mode file_extension mimetype name nbconvert_exporter pygments_lexer version
name version
ipython
3
.py
text/x-python
python
python
ipython3
3.7.3
description display_as has_thumbnail ipynb language layout name order permalink thumbnail title
How to make a streamline plot in Python. A streamline plot displays vector field data.
scientific
true
~notebook_demo/43
python
user-guide
Streamline Plots
13
python/streamline-plots/
thumbnail/streamline.jpg
Python Streamline Plots | plotly

A Streamline plot is a representation based on a 2-D vector field interpreted as a velocity field, consisting of closed curves tangent to the velocity field. In the case of a stationary velocity field, streamlines coincide with trajectories (see also the Wikipedia page on streamlines, streaklines and pathlines).

For the streamline figure factory, one needs to provide

  • uniformly spaced ranges of x and y values (1D)
  • 2-D velocity values u and v defined on the cross-product (np.meshgrid(x, y)) of x and y.

Velocity values are interpolated when determining the streamlines. Streamlines are initialized on the boundary of the x-y domain.

Basic Streamline Plot

import plotly.figure_factory as ff

import numpy as np

x = np.linspace(-3, 3, 100)
y = np.linspace(-3, 3, 100)
Y, X = np.meshgrid(x, y)
u = -1 - X**2 + Y
v = 1 + X - Y**2

# Create streamline figure
fig = ff.create_streamline(x, y, u, v, arrow_scale=.1)
fig.show()

Streamline and Source Point Plot

import plotly.figure_factory as ff
import plotly.graph_objects as go

import numpy as np

N = 50
x_start, x_end = -2.0, 2.0
y_start, y_end = -1.0, 1.0
x = np.linspace(x_start, x_end, N)
y = np.linspace(y_start, y_end, N)
X, Y = np.meshgrid(x, y)
source_strength = 5.0
x_source, y_source = -1.0, 0.0

# Compute the velocity field on the mesh grid
u = (source_strength/(2*np.pi) *
     (X - x_source)/((X - x_source)**2 + (Y - y_source)**2))
v = (source_strength/(2*np.pi) *
     (Y - y_source)/((X - x_source)**2 + (Y - y_source)**2))

# Create streamline figure
fig = ff.create_streamline(x, y, u, v,
                           name='streamline')

# Add source point
fig.add_trace(go.Scatter(x=[x_source], y=[y_source],
                          mode='markers',
                          marker_size=14,
                          name='source point'))

fig.show()

See also

For a 3D version of streamlines, use the trace go.Streamtube documented here.

For representing the 2-D vector field as arrows, see the quiver plot tutorial.

Reference

help(ff.create_streamline)