倒勾图示例

倒勾图的示例:

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. x = np.linspace(-5, 5, 5)
  4. X, Y = np.meshgrid(x, x)
  5. U, V = 12 * X, 12 * Y
  6. data = [(-1.5, .5, -6, -6),
  7. (1, -1, -46, 46),
  8. (-3, -1, 11, -11),
  9. (1, 1.5, 80, 80),
  10. (0.5, 0.25, 25, 15),
  11. (-1.5, -0.5, -5, 40)]
  12. data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
  13. ('u', np.float32), ('v', np.float32)])
  14. fig1, axs1 = plt.subplots(nrows=2, ncols=2)
  15. # Default parameters, uniform grid
  16. axs1[0, 0].barbs(X, Y, U, V)
  17. # Arbitrary set of vectors, make them longer and change the pivot point
  18. # (point around which they're rotated) to be the middle
  19. axs1[0, 1].barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')
  20. # Showing colormapping with uniform grid. Fill the circle for an empty barb,
  21. # don't round the values, and change some of the size parameters
  22. axs1[1, 0].barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
  23. sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))
  24. # Change colors as well as the increments for parts of the barbs
  25. axs1[1, 1].barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
  26. barbcolor=['b', 'g'], flip_barb=True,
  27. barb_increments=dict(half=10, full=20, flag=100))
  28. # Masked arrays are also supported
  29. masked_u = np.ma.masked_array(data['u'])
  30. masked_u[4] = 1000 # Bad value that should not be plotted when masked
  31. masked_u[4] = np.ma.masked
  32. # Identical plot to panel 2 in the first figure, but with the point at
  33. # (0.5, 0.25) missing (masked)
  34. fig2, ax2 = plt.subplots()
  35. ax2.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')
  36. plt.show()

倒勾图示例

倒勾图示例2

参考

此示例中显示了以下函数,方法和类的使用:

  1. import matplotlib
  2. matplotlib.axes.Axes.barbs
  3. matplotlib.pyplot.barbs

下载这个示例