
- Matplotlib - Home
- Matplotlib - Introduction
- Matplotlib - Vs Seaborn
- Matplotlib - Environment Setup
- Matplotlib - Anaconda distribution
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - Simple Plot
- Matplotlib - Saving Figures
- Matplotlib - Markers
- Matplotlib - Figures
- Matplotlib - Styles
- Matplotlib - Legends
- Matplotlib - Colors
- Matplotlib - Colormaps
- Matplotlib - Colormap Normalization
- Matplotlib - Choosing Colormaps
- Matplotlib - Colorbars
- Matplotlib - Working With Text
- Matplotlib - Text properties
- Matplotlib - Subplot Titles
- Matplotlib - Images
- Matplotlib - Image Masking
- Matplotlib - Annotations
- Matplotlib - Arrows
- Matplotlib - Fonts
- Matplotlib - Font Indexing
- Matplotlib - Font Properties
- Matplotlib - Scales
- Matplotlib - LaTeX
- Matplotlib - LaTeX Text Formatting in Annotations
- Matplotlib - PostScript
- Matplotlib - Mathematical Expressions
- Matplotlib - Animations
- Matplotlib - Celluloid Library
- Matplotlib - Blitting
- Matplotlib - Toolkits
- Matplotlib - Artists
- Matplotlib - Styling with Cycler
- Matplotlib - Paths
- Matplotlib - Path Effects
- Matplotlib - Transforms
- Matplotlib - Ticks and Tick Labels
- Matplotlib - Radian Ticks
- Matplotlib - Dateticks
- Matplotlib - Tick Formatters
- Matplotlib - Tick Locators
- Matplotlib - Basic Units
- Matplotlib - Autoscaling
- Matplotlib - Reverse Axes
- Matplotlib - Logarithmic Axes
- Matplotlib - Symlog
- Matplotlib - Unit Handling
- Matplotlib - Ellipse with Units
- Matplotlib - Spines
- Matplotlib - Axis Ranges
- Matplotlib - Axis Scales
- Matplotlib - Axis Ticks
- Matplotlib - Formatting Axes
- Matplotlib - Axes Class
- Matplotlib - Twin Axes
- Matplotlib - Figure Class
- Matplotlib - Multiplots
- Matplotlib - Grids
- Matplotlib - Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Subplots() Function
- Matplotlib - Subplot2grid() Function
- Matplotlib - Anchored Artists
- Matplotlib - Manual Contour
- Matplotlib - Coords Report
- Matplotlib - AGG filter
- Matplotlib - Ribbon Box
- Matplotlib - Fill Spiral
- Matplotlib - Findobj Demo
- Matplotlib - Hyperlinks
- Matplotlib - Image Thumbnail
- Matplotlib - Plotting with Keywords
- Matplotlib - Create Logo
- Matplotlib - Multipage PDF
- Matplotlib - Multiprocessing
- Matplotlib - Print Stdout
- Matplotlib - Compound Path
- Matplotlib - Sankey Class
- Matplotlib - MRI with EEG
- Matplotlib - Stylesheets
- Matplotlib - Background Colors
- Matplotlib - Basemap
- Matplotlib - Event Handling
- Matplotlib - Close Event
- Matplotlib - Mouse Move
- Matplotlib - Click Events
- Matplotlib - Scroll Event
- Matplotlib - Keypress Event
- Matplotlib - Pick Event
- Matplotlib - Looking Glass
- Matplotlib - Path Editor
- Matplotlib - Poly Editor
- Matplotlib - Timers
- Matplotlib - Viewlims
- Matplotlib - Zoom Window
- Matplotlib Widgets
- Matplotlib - Cursor Widget
- Matplotlib - Annotated Cursor
- Matplotlib - Buttons Widget
- Matplotlib - Check Buttons
- Matplotlib - Lasso Selector
- Matplotlib - Menu Widget
- Matplotlib - Mouse Cursor
- Matplotlib - Multicursor
- Matplotlib - Polygon Selector
- Matplotlib - Radio Buttons
- Matplotlib - RangeSlider
- Matplotlib - Rectangle Selector
- Matplotlib - Ellipse Selector
- Matplotlib - Slider Widget
- Matplotlib - Span Selector
- Matplotlib - Textbox
- Matplotlib Plotting
- Matplotlib - Line Plots
- Matplotlib - Area Plots
- Matplotlib - Bar Graphs
- Matplotlib - Histogram
- Matplotlib - Pie Chart
- Matplotlib - Scatter Plot
- Matplotlib - Box Plot
- Matplotlib - Arrow Demo
- Matplotlib - Fancy Boxes
- Matplotlib - Zorder Demo
- Matplotlib - Hatch Demo
- Matplotlib - Mmh Donuts
- Matplotlib - Ellipse Demo
- Matplotlib - Bezier Curve
- Matplotlib - Bubble Plots
- Matplotlib - Stacked Plots
- Matplotlib - Table Charts
- Matplotlib - Polar Charts
- Matplotlib - Hexagonal bin Plots
- Matplotlib - Violin Plot
- Matplotlib - Event Plot
- Matplotlib - Heatmap
- Matplotlib - Stairs Plots
- Matplotlib - Errorbar
- Matplotlib - Hinton Diagram
- Matplotlib - Contour Plot
- Matplotlib - Wireframe Plots
- Matplotlib - Surface Plots
- Matplotlib - Triangulations
- Matplotlib - Stream plot
- Matplotlib - Ishikawa Diagram
- Matplotlib - 3D Plotting
- Matplotlib - 3D Lines
- Matplotlib - 3D Scatter Plots
- Matplotlib - 3D Contour Plot
- Matplotlib - 3D Bar Plots
- Matplotlib - 3D Wireframe Plot
- Matplotlib - 3D Surface Plot
- Matplotlib - 3D Vignettes
- Matplotlib - 3D Volumes
- Matplotlib - 3D Voxels
- Matplotlib - Time Plots and Signals
- Matplotlib - Filled Plots
- Matplotlib - Step Plots
- Matplotlib - XKCD Style
- Matplotlib - Quiver Plot
- Matplotlib - Stem Plots
- Matplotlib - Visualizing Vectors
- Matplotlib - Audio Visualization
- Matplotlib - Audio Processing
- Matplotlib Useful Resources
- Matplotlib - Quick Guide
- Matplotlib - Cheatsheet
- Matplotlib - Useful Resources
- Matplotlib - Discussion
Matplotlib - Quiver Plot
A quiver plot is a type of graph used to visualize vector fields, which represent both direction and magnitude. In simple terms, it shows arrows on a grid, where each arrow represents a vector pointing in a specific direction with a certain length.
- Imagine you are studying the wind patterns over a region. You want to visualize both the direction and strength of the wind at various points across the area.
- You can use the quiver plot for this visualization, where each arrow in the plot represents the direction the wind is blowing, while the length of the arrow indicates the wind speed.
By looking at the quiver plot, you can quickly see how the wind flows across the region and identify areas with stronger or weaker winds −

Quiver Plot in Matplotlib
In Matplotlib, a quiver plot is a visualization that represents vector fields using arrows. We can use the quiver() function from the 'pyplot' module to create arrows for displaying a quiver plot in Matplotlib.
This function takes the X and Y coordinates (and Z for a three-dimensional object) of a vector field, and represents its direction and magnitude as an arrow(s).
Lets start by drawing a basic quiver plot.
Basic Quiver Plot
A basic quiver plot in Matplotlib visualizes a vector in a two-dimensional space. It consists of an arrow, where the length and direction of the arrow indicate the magnitude and direction of a vector.
Example
In the following example, we are creating a basic quiver plot to represent a vector as an arrow. We first specify the starting position of the arrow by 'x_pos' and 'y_pos' which represent the X and Y coordinates, respectively.
The direction of the arrow is determined by 'x_direct' and 'y_direct' for the x-axis and the y-axis, respectively. The resultant plot shows an arrow originating at (1, 1) and pointing in a certain direction −
import numpy as np import matplotlib.pyplot as plt # Defining the arrows x_pos = 1 y_pos = 1 x_direct = 2 y_direct = 1 # Creating the plot fig, ax = plt.subplots(figsize=(12, 7)) # Plotting the quiver ax.quiver(x_pos, y_pos, x_direct, y_direct, angles='xy', scale_units='xy', scale=1, color='green', width=0.02, label='Arrow') # Setting axis limits ax.set_xlim([0, 4]) ax.set_ylim([0, 3]) ax.set_title('Basic Quiver Plot') # Displaying the plot plt.show()
Output
Following is the output of the above code −

Meshgrid Quiver Plot
In Matplotlib, a meshgrid quiver plot visually represents evenly spaced vectors as distinct arrows. The magnitude and direction of the entire vector field can be calculated by summing the magnitudes and directions of individual arrows.
Example
In here, we are creating a meshgrid quiver plot of multiple vector fields by arranging the arrows on a 2D grid. The X and Y coordinates range from 0 to 4, with a step count of 0.3. The direction of each vector field is calculated by parameterizing the X and Y coordinates with the sine and cosine angles, respectively. This results in a plot where multiple vector fields are represented as different arrows −
import numpy as np import matplotlib.pyplot as plt # Creating the arrow x = np.arange(0, 4, 0.3) y = np.arange(0, 4, 0.3) X, Y = np.meshgrid(x, y) u = np.sin(X)*Y v = np.cos(Y)*Y # Creating the plot fig, ax = plt.subplots(figsize =(14, 8)) # Plotting the quiver ax.quiver(X, Y, u, v) # Setting axis limits ax.axis([-0.3, 2.3, -0.3, 2.3]) ax.set_aspect('equal') ax.set_title('Meshgrid Quiver Plot') # Displaying the plot plt.show()
Output
Output of the above code is as follows −

Gradient Quiver Plot
A gradient quiver plot in Matplotlib represents a visualization of a vector field with a changing gradient in a 2D space. The gradient indicates the strength of the vector field, represented by the number of arrows. The more arrows there are in a particular region, the stronger the vector field is in that area.
Example
The following example creates a gradient quiver plot to show the change in strength of a vector field. The X and Y coordinates range from -2 to 2, with a step count of 0.1. The gradient is calculated as the change in direction of X and Y values, represented by 'dx' and 'dy' −
import numpy as np import matplotlib.pyplot as plt # Creating the arrows x = np.arange(-2, 2, 0.1) y = np.arange(-2, 2, 0.1) # Creating a gradient function X, Y = np.meshgrid(x, y) z = np.sin(X) * np.cos(Y) dx, dy = np.gradient(z) # Creating the plot fig, ax = plt.subplots(figsize=(9, 9)) # Plotting the quiver ax.quiver(X, Y, dx, dy) # Setting axis limits ax.set_aspect('equal') ax.set_title('Gradient Quiver Plot') # Displaying the plot plt.show()
Output
After executing the above code, we get the following output −

Colored Quiver Plot
In Matplotlib, a colored quiver plot is an advance version of the basic quiver plot where the vector field is represented by arrows of different colors. The color of the arrows depends on specific parameters such as distance from origin, strength, or direction.
Example
Now, we are creating a colored quiver plot to represent a vector field. We set the starting position of the arrows withing the range 0 to 2 and parameterize the direction based on the X and Y values.
Then, we assign a color to each arrow based on its distance from the center of the field. Arrow closer to the center are darker in color while arrows further away are lighter in color −
import numpy as np import matplotlib.pyplot as plt # Creating the arrow x = np.arange(0, 2 * np.pi + 2 * np.pi / 20, 2 * np.pi / 20) y = np.arange(0, 2 * np.pi + 2 * np.pi / 20, 2 * np.pi / 20) X, Y = np.meshgrid(x, y) u = np.cos(X) * np.sin(Y) v = np.sin(X) * np.cos(Y) # Defining the color color = np.sqrt(u**2 + v**2) # Creating the plot fig, ax = plt.subplots(figsize=(14, 9)) # Plotting the quiver ax.quiver(X, Y, u, v, color, alpha=1, cmap='viridis') # Setting axis limits ax.axis([0, 2 * np.pi, 0, 2 * np.pi]) ax.set_aspect('equal') ax.set_title('Colored Quiver Plot') # Displaying plot plt.show()
Output
The output obtained is as shown below −
