👀
Crash Visualization
  • Welcome
  • Preface
    • Who the book is written for
    • How the book is organized
  • 1. Introduction of Data Visualization
    • 1.1 What is data visualization?
    • 1.2 Why does visualization matter?
  • 2. Tricks in Visualization
    • 2.1 Choose Appropriate Chart
    • 2.2 Features of Charts
      • 2.2.1 Table
      • 2.2.2 Column Chart
      • 2.2.3 Line Chart
      • 2.2.4 Pie Chart
      • 2.2.5 Scatter Chart
      • 2.2.6 Map Chart
    • 2.3 Misused Graph
    • 2.4 Tips in Visualization
  • 3. Matplotlib
    • 3.1 Basic Concepts
    • 3.2 Line Chart
    • 3.3 Area Chart
    • 3.4 Column Chart
    • 3.5 Histogram Chart
    • 3.6 Scatter Chart
    • 3.7 Lollipop Chart
    • 3.8 Pie Chart
    • 3.9 Venn Chart
    • 3.10 Waffle Chart
    • 3.11 Animation
  • 4. Seaborn
    • 4.1 Trends
    • 4.2 Ranking
      • 4.2.1 Barplot
      • 4.2.2 Boxplot
    • 4.3 Composition
      • 4.3.1 Stacked Chart
    • 4.4 Correlation
      • 4.4.1 Scatter Plot
      • 4.4.2 Linear Relationship
      • 4.4.3 Heatmap
      • 4.4.4 Pairplot
    • 4.5 Distribution
      • 4.5.1 Boxplot
      • 4.5.2 Violin plot
      • 4.5.3 Histogram plot
      • 4.5.4 Density plot
      • 4.5.5 Joint plot
  • 5. Bokeh
    • 5.1 Basic Plotting
    • 5.2 Data Sources
    • 5.3 Annotations
    • 5.4 Categorical Data
    • 5.5 Presentation and Layouts
    • 5.6 Linking and Interactions
    • 5.7 Network Graph
    • 5.8 Widgets
  • 6. Plotly
    • 6.1 Fundamental Concepts
      • 6.1.1 Plotly Express
      • 6.1.2 Plotly Graph Objects
    • 6.2 Advanced Charts
      • 6.2.1 Advanced Scatter Chart
      • 6.2.2 Advanced Bar Chart
      • 6.2.3 Advanced Pie Chart
      • 6.2.4 Advanced Heatmap
      • 6.2.5 Sankey Chart
      • 6.2.6 Tables
    • 6.3 Statistical Charts
      • 6.3.1 Common Statistical Charts
      • 6.3.2 Dendrograms
      • 6.3.3 Radar Chart
      • 6.3.4 Polar Chart
      • 6.3.5 Streamline Chart
    • 6.4 Financial Charts
      • 6.4.1 Funnel Chart
      • 6.4.2 Candlestick Chart
      • 6.4.3 Waterfall Chart
  • Support
    • Donation
Powered by GitBook
On this page
  • 1. Streamline Plot
  • 2. Quiver Plot
  • 3. 3-D Quiver Plot

Was this helpful?

  1. 6. Plotly
  2. 6.3 Statistical Charts

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.

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.

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.

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()

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()

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()

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()

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).

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()

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()

Previous6.3.4 Polar ChartNext6.4 Financial Charts

Last updated 4 years ago

Was this helpful?

Basic Streamline Plot
Streamline with source points
Basic Quiver Plot
Quiver plot with source points