1

I have two arrays (vel_y,vel_z) representing velocities in the y and z directions, respectively, that are both shaped as (512,512) that I am attempting to represent using a quiver plot. Here is how I plotted the quiver:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,512,num=512)
[X,Y] = np.meshgrid(x,x)
fig, ax = plt.subplots(figsize=(7,7))
ax.quiver(X,Y,vel_y,vel_z,np.arctan2(vel_z,vel_y),pivot='mid',units='x',scale=2)

The arctan2() call is so that different orientations are colored differently as in this answer. Obviously plotting all 5122 of these arrows makes for a jumbled and difficult to parse plot, which you can see here: Quiver Plot.


I was wondering if there was a better way to scale/represent the arrows so that it is more readable?

However, the main question I have is how I could 'downsample' this velocity information to go from plotting 5122 arrows to 1002 for example. Would this require interpolation between points where the velocity is defined?

Thank you!

Sam K
  • 27
  • 3

1 Answers1

1

The simple way to do this is simply to take one point over N in each vectors given to quiver.

For a given np.array, you can do this using the following syntax: a[::N]. If you have multiple dimensions, repeat this in each dimension (you can give different slip for each dimension): a[::N1, ::N2].

In your case:

N1 = 5
N2 = 5
ax.quiver(X[::N1, ::N2], Y[::N1, ::N2], vel_y[::N1, ::N2], vel_z[::N1, ::N2], np.arctan2(vel_z,vel_y)[::N1, ::N2], pivot='mid',units='x',scale=2)

You don't need interpolation, unless you want to plot velocities at points not defined in the grid where you have your measurements/simulations/whatever.

Liris
  • 1,399
  • 3
  • 11
  • 29