Python

Plotly figure_factory Modules Create Streamline Plots

Streamlines are types of plots used to represent velocity fields. A streamline uses closed curves that tangent to the velocity field.

In this article, we will explore how we can create streamline plots using the Plotly figure_factory module.

Function Syntax and Parameter List

The function syntax is provided below:

plotly.figure_factory.create_streamline(x, y, u, v, density=1, angle=0.3490658503988659,

arrow_scale=0.09, **kwargs)

Required parameters:

  1. X – 1 dimensional, evenly spaced list or array
  2. Y – 1 dimensional, evenly spaced list or array
  3. U – 2-dimensional array
  4. V – 2-dimensional array
  5. density – sets the density of the streamlines
  6. angle – angle of arrowhead in radians
  7. arrow_scale – scale length of the arrowhead

Streamline Plot With Figure Factory

The following code illustrates how to create a basic streamline plot using Plotly figure_factory.

From plotly.figure_factory import create_streamline
import numpy as np
import math
x = np.linspace(-1, 1, 10)
y = np.linspace(-1, 1, 10)
Y, X = np.meshgrid(x, y)
u = -1 – X**2 + Y
v = 1 + X – Y**2
u = u.T
v = v.T
fig = create_streamline(x, y, u, v)
fig.show()

The resulting streamline figure is shown below:

Show Source Point

To include the source point of the arrow heads, we can run the following:

from plotly.figure_factory import create_streamline
import numpy as np
import math
import plotly.graph_objects as go
x = np.linspace(-1, 1, 10)
y = np.linspace(-1, 1, 10)
Y, X = np.meshgrid(x, y)
u = -1 - X**2 + Y
v = 1 + X - Y**2
u = u.T
v = v.T
fig = create_streamline(x, y, u, v)
fig.add_trace(go.Scatter(x=[-1.0], y=[0.0],
                          mode='markers',
                          marker_size=15))
fig.show()

Output:

Conclusion

This article discussed how to create streamline plots using Plotly figure_factory modules with the function syntax and parameters provided. In addition, the source points of the arrow heads were included.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list