Skip to content Skip to sidebar Skip to footer

How To Plot Streamlines With Matplotlib Given 1-d Arrays Of X Cords, Y Cords, U Components And V Components

Before I start, I'll add that I have not been using Python for very long at all! There were similar questions on StackOverflow before I posted this but I could not get a useable an

Solution 1:

A prior note: numpy 4D to 1D is cheap and fast.

In any case, where 1D vector shall take place in processing, np gives you a powerful trick to use it's concept of .view. Technically you let numpy just refer to a part ( or all ) of the original numpy.ndarray as you need, without any duplication of data-cells ( which is pretty important once sizes grow and in-RAM inefficient data structures stop work ).

One may simply store complete 4D | 5D | nD coordinates in a fully equipped array an smart-refer to 1D-components as needed:

XYZUV_any_dimensionalityObservationDataPointsARRAY[:,0] == ( x0, y0, z0, u0, v0 )XYZUV_any_dimensionalityObservationDataPointsARRAY[:,1] == ( x1, y1, z1, u1, v1 )# and still use 1D-component vectors, where appropriate ( without DUPs )XYZUV_any_dimensionalityObservationDataPointsARRAY[0,:] == X      # 0-based indexXYZUV_any_dimensionalityObservationDataPointsARRAY[1,:] == YXYZUV_any_dimensionalityObservationDataPointsARRAY[2,:] == Z
...
XYZUV_any_dimensionalityObservationDataPointsARRAY[4,:] == V

May glue them together

XYUV_ObservationDataPoints4DARRAY = np.vstack( ( X,
                                                 Y,
                                                 U,
                                                 V
                                                 )    # needs a tuple
                                               )

Plot

So forth the plot process can still re-use partial views once needed to be fed into appropriate function syntax:

X kept as 1D

XYZUV[0,:]             #  Xviaaviewtaken: 1stcolumnandallrows +[ NO RAM ]

Y kept as 1D

XYZUV[1,:]             #  Yviaaviewtaken: 2stcolumnandallrows +[ NO RAM ]

UV kept as 2D

XYZUV[3:5,:]           # UV via a view taken at allcolumns in [3:5]  +[ NO RAM ]

UV glued to 2D

np.vstack( ( U, V ) )  # UV via an ad-hoc *stack() -- will allocate   +[new RAM ]

Plotting XYUV

Post a Comment for "How To Plot Streamlines With Matplotlib Given 1-d Arrays Of X Cords, Y Cords, U Components And V Components"