Python中的 Matplotlib.pyplot.barbs()
Matplotlib是一个Python绑定库,它为用户提供了一个类似于 MATLAB 的绘图框架。 Matplotlib 可用于Python脚本、 Python和 IPython shell、Web 应用程序服务器以及各种图形用户界面工具包,如 Tkinter、awxPython 等。
注意:有关更多信息,请参阅Python Matplotlib - 概述
Matplotlib.pyplot.barbs()
matplotlib.pyplot.barbs
方法用于绘制倒钩的 2D 字段。
什么是倒钩?
倒钩在气象学中主要用于绘制风速和风向,但也可用于绘制任何二维向量。与箭头相比,倒钩能够提供有关矢量幅度的更精确和定量的信息。这主要是因为箭头使用它们的长度来表示矢量的大小,而倒钩使用三角形或斜线,如下所示:
/\ \
/ \ \
/ \ \ \
/ \ \ \
------------------------------
- 幅度的最大增量由三角形(或标志)表示
- 最小增量是半线
Syntax : matplotlib.pyplot.barbs(x_coordinate, y_coordinate, x_direction, y_direction, [colour])
Parameters:
x_coordinate : x-coordinate of the barb location
(may be a 2-dimensional array in case of multiple barbs)
y_coordinate : y-coordinate of the barb location
(may be a 2-dimensional array in case of multiple barbs)
x_direction : x-component of the direction of barb shaft
(may be a 2-dimensional array in case of multiple barbs)
y_direction : y-component of the direction of the barb shaft
(may be a 2-dimensional array in case of multiple barbs)
colour (optional): specifies the colour of the barb in the graph
Optional Parameters
length : length of the barb in points, other parts of the barb are scaled against this
pivot : part of the barb anchored to the grid; the barb rotates about this point. Maybe a number, which shifts the barb that many points away from the grid point
Return Value : Returns a 2D graph with arrows plotted
笔记 :
- 如果未给出倒钩位置的x 坐标和y 坐标,则它们将基于x_direction和y_direction生成为均匀整数网格网格
- 如果x-coordinate和y-coordinate是一维的,而x_direction和y_direction是二维的,那么x-coordinate和y-coordinate将使用
x, y=numpy.meshgrid(x, y)
.在这种情况下, x 坐标和y 坐标的长度必须与x_direction和y_direction的行和列尺寸相匹配
示例代码:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-5, 5, 5)
X, Y = np.meshgrid(x, x)
U, V = 12 * X, 12 * Y
data = [(-1.5, .5, -6, -6),
(1, -1, -46, 46),
(-3, -1, 11, -11),
(1, 1.5, 80, 80),
(0.5, 0.25, 25, 15),
(-1.5, -0.5, -5, 40)]
data = np.array(data, dtype=[('x', np.float32),
('y', np.float32),
('u', np.float32),
('v', np.float32)])
plt.barbs(X, Y, U, V)
输出 :