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
- 2-D velocity values
vdefined on the cross-product (
np.meshgrid(x, y)) of
Velocity values are interpolated when determining the streamlines. Streamlines are initialized on the boundary of the
Basic Streamline Plot¶
Streamline plots can be made with a figure factory as detailed in this page.
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()
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()
What About Dash?¶
Learn about how to install Dash at https://dash.plot.ly/installation.
Everywhere in this page that you see
fig.show(), you can display the same figure in a Dash application by passing it to the
figure argument of the
Graph component from the built-in
dash_core_components package like this:
import plotly.graph_objects as go # or plotly.express as px fig = go.Figure() # or any Plotly Express function e.g. px.bar(...) # fig.add_trace( ... ) # fig.update_layout( ... ) from dash import Dash, dcc, html app = Dash() app.layout = html.Div([ dcc.Graph(figure=fig) ]) app.run_server(debug=True, use_reloader=False) # Turn off reloader if inside Jupyter