I was wondering whether it is possible to create a 3D vector Field PLot from a 4D numpy array.
The array is in the shape (10,10,10,3) which is basically the three vector components at each respective grid point. Grid spacing is 1.
There is a matplotlib function ax.quiver() (https://matplotlib.org/stable/gallery/mplot3d/quiver3d.html) that I would like to use. It can be used for irregular grid, which is why it takes 6 meshgrids as input (x,y,z,u,v,w) for the grid and the vector components respectively.
I know how to create the xyz meshgrids, but I am not sure how to extract the vector components uvw from my 4d array.
Help would be appreciated!
Related
I would like to create 3D array of points, where I have list of three coordinates (x,y,z) and value at this coordinate. I have 6308 points of measurement.
For reference, I pasted the data in the pastebin. The purpose is to create 3D Numpy array and calculate 3D Fourier transform.
I would like to arrange this data into 3D array. I tried to use xarray module for this - but the xarray.DataArray needs numpy.ndarray as its input.
I tried to create meshgrid and put data value into coordinates but I had MemoryError.
Finally, I tried to make test random array:
out = np.zeros(shape=(6308,6308,6308))
but I also had the error:
MemoryError: Unable to allocate 1.83 TiB for an array with shape (6308, 6308, 6308) and data type float64
And at this point I don't have any idea how to arrange the data into 3D array for 3D Fourier transform calculation. Is it even possible?
I have two matrices: m x m and m x 1.
The 2D matrix's data is dependent on the 1D matrix, so I want to show this case in a one plot.
Earlier, to visualize the 2D matrix I used a heatmap and also now I think about using it.
Both matrices have the same label ticks, so I got an idea to double the 1D matrix and place them next to the 2D matrix's labels to let them share the same label ticks:
Is it possible to achieve such a plot^ in Python, especially in seaborn or matplotlib?
Or maybe there is another, better way to visualize such a data?
For now, I see here one issue - a lack of a legend for 1D matrices, but I have no idea where and how it should be placed.
I've got a 3D numpy array with elements being 0 or 1. What I need is to plot the array with the indices as the coordinates (x,y,z) and the colour of the point depending upon if the value contained in the element is 0 or 1.
I'm not very great at matplotlib or anything, so looking for recommendations.
I want to visualize such 4D data in the 2D plane. Is there any way to do that?
You can use principal component analysis to reduce the dimensions. Sklearn has an easy to use package. PCA uses eigen vectors to determine the most 'important' directions in the higher dimensional space and projects the values into the lower dimensional space. Although keep in mind the generated vectors do lose some information from the higher dimensional input.
You can use pairs plot. Look at this link: Visualizing Data with Pairs Plots in Python.
Depending on the data type, you can plot them on a 2d field with the following dimensions:
Dim 1-2: X and Y axes
Dim 3: plotted point size
Dim 4: plotted point color gradient
Or if you do it with a 3D software, you can plot in 3D, with all the point plotted with color gradient. While rotating the field, you can have vision on all dimensions.
I have a 3D array created using the numpy mgrid command so that each element has a certain value and the indexes retain the spatial information. For example, if one summed over the z-axis (3rd dimension) then the the resultant 2D array could be used in matplotlib with the function imshow() to obtain an image with different binned pixel values.
My question is: How can I obtain the index values for each element in this grid (a,b,c)?
I need to use the index values to calculate the relative angle of each point to the origin of the grid. (eg. theta=sin-1(sqrt(x^2+y^2)/sqrt(x^2+y^2+z^2))
Maybe this can be translated to another 3D grid where each element is the array [a,b,c]?
I'm not exactly clear on your meaning, but if you are looking for 3d arrays that contain the indices x, y, and z, then the following may suit your needs; assume your data is held in a 3D array called "abc":
import numpy as nm
x,y,z = nm.mgrid[[slice(dm) for dm in abc.shape]]