Python中的 Matplotlib.pyplot.quiver()
Matplotlib是一个Python绑定库,它为用户提供了一个类似于 MATLAB 的绘图框架。 Matplotlib 可用于Python脚本、 Python和 IPython shell、Web 应用程序服务器以及各种图形用户界面工具包,如 Tkinter、awxPython 等。
Matplotlib.pyplot.quiver()
matplotlib.pyplot.quiver
方法用于绘制 2D 箭头字段。
Syntax: matplotlib.pyplot.quiver(x_coordinate, y_coordinate, x_direction, y_direction)
Parameters:
x_coordinate : x-coordinate of the arrow location
y_coordinate : y-coordinate of the arrow location
x_direction : x-component of the direction of the arrow
y_direction : y-component of the direction of the arrow
Optional Parameters:
scale: used to set the scale of the graph
scale_units: used to set the units of the plane with respect to x and y
angle: used to determine the angle of the arrow vectors plotted
Return Value : Returns a 2D graph with arrows plotted
示例 #1
#Python program to explain
# matplotlib.pyplot.quiver method
import matplotlib.pyplot as plt
import numpy as np
#defining necessary arrays
x = np.linspace(0,2,8)
y = np.linspace(2,0,8)
x_dir = y_dir = np.zeros((8,8))
y_dir[5,5] = 0.2
#plotting the 2D graph
plt.quiver(x, y, x_dir, y_dir, scale=1)
输出:
示例 #2
使用quiver
方法在图形上绘制多个箭头
# Python program to explain
# matplotlib.pyplot.quiver method
# importing necessary libraries
import matplotlib.pyplot as plt
# defining necessary arrays
x_coordinate = [0, 1.5]
y_coordinate = [0.5, 1.5]
x_direction = [1, -0.5]
y_direction = [1, -1]
# plotting the graph
plt.quiver(x_coordinate, y_coordinate,
x_direction, y_direction,
scale_units ='xy', scale = 1.)
输出: