# 6.3.5 Streamline Chart

### 1. Streamline Plot

Streamlines are a family of curves that are instantaneously tangent to the velocity vector of the flow. These show the direction in which a massless fluid element will travel at any point in time.&#x20;

Streamlines can be useful in fluid dynamics. For example, Bernoulli's principle, which describes the relationship between pressure and velocity in an inviscid fluid, is derived for locations along a streamline.

{% hint style="info" %}
**It 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`.
  {% endhint %}

#### Basic streamline plot

```
import plotly.figure_factory as ff
import numpy as np

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

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

![Basic Streamline Plot](/files/-MDAQwiRYSExj9YBA_yY)

#### Streamline with source points

```
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=30,
                          name='source point',
                        marker=dict(color='gold')))
                        
fig.update_layout(template= 'plotly_dark')
fig.show()
```

![Streamline with source points](/files/-MDAQiZaGr3qX13cVRDD)

### 2. Quiver Plot

A quiver plot displays velocity vectors as arrows with components (u,v) at the points (x,y). This type of plot is useful in electrical engineers to visualize electrical potential and show stress gradients in Mechanical engineering.

#### Basic quiver plot

```
x,y = np.meshgrid(np.arange(0, 3, .25), np.arange(0, 3, .25))
u = -np.cos(x)*y
v = -np.sin(x)*y

fig = ff.create_quiver(x, y, u, v)
fig.show()
```

![Basic Quiver Plot](/files/-MDAQiZZXHSnSVmKT9Ni)

#### Quiver plot with source points

Just like the streamline plot, it is also possible to add source points to a quiver plot.

```
import numpy as np
x,y = np.meshgrid(np.arange(-2, 2, .25),
                  np.arange(-2, 2, .25))
z = x*np.exp(-x**2 - y**2)
v, u = np.gradient(z, .25, .25)

# Create quiver figure
fig = ff.create_quiver(x, y, u, v,
                       scale=.25,
                       arrow_scale=.5,
                       name='quiver',
                       line_width=2)

# Add points to figure
fig.add_trace(go.Scatter(x=[-.75, .75], y=[0,0],
                    mode='markers',
                    marker_size=20,
                    name='source point'))
fig.show()
```

![Quiver plot with source points](/files/-MDASwz_bll27v8XCLKy)

### 3. 3-D Quiver Plot

To make the graph more interesting and intuitive, we can draw a 3-D quiver plot, which is also called the "cone plot". Cone plots (also known as 3-D quiver plots) represent vector fields defined in some region of the 3-D space.

A vector field associates to each point of coordinates (x, y, z) a vector of components (u, v, w).&#x20;

#### Simple 3-D quiver plot

```
fig = go.Figure(data=go.Cone(x=[1], y=[1], z=[1], u=[1], v=[1], w=[0],
                                colorscale='hot'))
fig.update_layout(scene_camera_eye=dict(x=-0.75, y= 0.75, z=1.5))
fig.show()
```

![](/files/-MDAaC4S6hjaV2rGW7BD)

#### Customized 3-D quiver plot

```
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/vortex.csv")

fig = go.Figure(data = go.Cone(
    x=df['x'],
    y=df['y'],
    z=df['z'],
    u=df['u'],
    v=df['v'],
    w=df['w'],
    colorscale='Blues',
    sizemode="absolute",
    sizeref=60))

fig.update_layout(scene=dict(aspectratio=dict(x=1, y=1, z=0.8),
                             camera_eye=dict(x=1.2, y=1.2, z=0.6)),
                  template = 'plotly_dark' )

fig.show()
```

![](/files/-MDAaC4UxdTHONrGoulr)

####


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vecco-insight.gitbook.io/crash-visualization/plotly/6.3-statistical-charts/6.3.5-streamline-chart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
