1''' 2========= 3Barb Demo 4========= 5 6Demonstration of wind barb plots 7''' 8import matplotlib.pyplot as plt 9import numpy as np 10 11x = np.linspace(-5, 5, 5) 12X, Y = np.meshgrid(x, x) 13U, V = 12 * X, 12 * Y 14 15data = [(-1.5, .5, -6, -6), 16 (1, -1, -46, 46), 17 (-3, -1, 11, -11), 18 (1, 1.5, 80, 80), 19 (0.5, 0.25, 25, 15), 20 (-1.5, -0.5, -5, 40)] 21 22data = np.array(data, dtype=[('x', np.float32), ('y', np.float32), 23 ('u', np.float32), ('v', np.float32)]) 24 25fig1, axs1 = plt.subplots(nrows=2, ncols=2) 26# Default parameters, uniform grid 27axs1[0, 0].barbs(X, Y, U, V) 28 29# Arbitrary set of vectors, make them longer and change the pivot point 30# (point around which they're rotated) to be the middle 31axs1[0, 1].barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle') 32 33# Showing colormapping with uniform grid. Fill the circle for an empty barb, 34# don't round the values, and change some of the size parameters 35axs1[1, 0].barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False, 36 sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3)) 37 38# Change colors as well as the increments for parts of the barbs 39axs1[1, 1].barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r', 40 barbcolor=['b', 'g'], flip_barb=True, 41 barb_increments=dict(half=10, full=20, flag=100)) 42 43# Masked arrays are also supported 44masked_u = np.ma.masked_array(data['u']) 45masked_u[4] = 1000 # Bad value that should not be plotted when masked 46masked_u[4] = np.ma.masked 47 48# Identical plot to panel 2 in the first figure, but with the point at 49# (0.5, 0.25) missing (masked) 50fig2, ax2 = plt.subplots() 51ax2.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle') 52 53plt.show() 54 55############################################################################# 56# 57# ------------ 58# 59# References 60# """""""""" 61# 62# The use of the following functions, methods and classes is shown 63# in this example: 64 65import matplotlib 66matplotlib.axes.Axes.barbs 67matplotlib.pyplot.barbs 68