.create_quiver()
Published Feb 28, 2025Updated Mar 5, 2025
Contribute to Docs
The .create_quiver()
function in Plotly’s figure_factory
module generates a quiver plot, which is used to visualize vector fields. It is commonly applied in physics, fluid dynamics, and engineering to depict direction and magnitude of vectors in a given space.
Syntax
import plotly.figure_factory as ff
quiver = ff.create_quiver(
x, y, u, v,
scale=0.1,
arrow_scale=0.3,
angle=math.pi/9,
line=dict(color='blue', width=1)
)
Parameters:
x
: A list or NumPy array representing the x-coordinates of the arrow bases.y
: A list or NumPy array representing the y-coordinates of the arrow bases.u
: A list or NumPy array representing the x-components (horizontal) of the arrow vectors.v
: A list or NumPy array representing the y-components (vertical) of the arrow vectors.scale
(default=0.1
): A scaling factor for the arrow lengths.arrow_scale
(default=0.3
): Determines the size of the arrowhead.angle
(default=math.pi/9
): The opening angle of the arrowhead.line
(optional): A dictionary defining the line properties, such as color and width.
Examples
Basic Quiver Plot
In this example, a quiver plot is created to visualize a circular vector field where arrows radiate outward in a radial pattern:
import plotly.figure_factory as ffimport numpy as npimport plotly.graph_objects as go# Generate circular grid pointstheta = np.linspace(0, 2 * np.pi, 20)x = np.cos(theta) * 3y = np.sin(theta) * 3# Define vector components with radial patternu = -np.sin(theta)v = np.cos(theta)# Create quiver plotfig = ff.create_quiver(x, y, u, v, scale=0.2, arrow_scale=0.5)fig.update_layout(title="Circular Quiver Plot")fig.show()
The output will be:
Customized Quiver Plot
This example demonstrates how to customize arrow styles in a quiver plot by modifying colors, line width, and scaling:
import plotly.figure_factory as ffimport numpy as npimport plotly.graph_objects as go# Generate structured gridx, y = np.meshgrid(np.linspace(-5, 5, 10), np.linspace(-5, 5, 10))u = -y / np.sqrt(x**2 + y**2)v = x / np.sqrt(x**2 + y**2)# Flatten arrays for plottingx, y, u, v = x.flatten(), y.flatten(), u.flatten(), v.flatten()# Create quiver plot with optimized arrow sizefig = ff.create_quiver(x, y, u, v, scale=1, arrow_scale=0.5, line=dict(color='red', width=2))fig.update_layout(title="Grid-Based Quiver Plot")fig.show()
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Plotly on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours