English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Matplotlib 2D Arrow Plot

Arrow plots display velocity vectors as arrows, with components (u, v) located at the point (x, y).

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
quiver(x,y,u,v)

The above command draws vectors as arrows at the specified coordinates in the corresponding elements of x and y.

Parameter

The following table lists the parameters of the quiver() function -

x - 1D or2D array, sequence. x coordinate of arrow position y - 1D or2D array, sequence. y coordinate of arrow position u - 1D or2D array, sequence. x component of arrow vector v - 1D or2D array, sequence. y component of arrow vector c - 1D or2D array, sequence. x coordinate of arrow position

The following code draws a simple arrow plot -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
#! /usr/bin/env python
#coding=utf-8
import matplotlib.pyplot as plt
import numpy as np
import math
import seaborn as sns
plt.rcParams['font.sans']-serif'] = ['SimHei']  # Step 1 (replace sans-serif font)
plt.rcParams['axes.unicode_minus'] = False  # Original from [Lidi Huo], commercial转载 please contact the author for authorization, non-commercial please keep the original link:
x, y = np.meshgrid(np.arange(-2, 2, .2), np.arange(-2, 2, .25)
z = x*np.exp(-x**2 - y**2)
v, u = np.gradient(z, .2, .2)
fig, ax = plt.subplots()
q = ax.quiver(x, y, u, v)
plt.show()

Execute the above example code to get the following results -