slicing volume rendering graph in python - python

I have an input data with each row having (x,y,z,data), i.e., each coordinate (x,y,z) has a value "data". I would like to make a slicing volumetric graph like below in python. I am new to python, any tips would be much appreciated. see here for the example graph

If you have your data organized as a 2D array (n-points x 4) [x,y,z,data] (this can also be refered to as a point-cloud representations) and you want to display it as a volume rendering. You have to first resample it as a 3D array (interpolate 3D volume with numpy and or scipy) and then create an isosurface using marching cubes (How to display a 3D plot of a 3D array isosurface in matplotlib mplot3D or similar?)
You can also plot the values using a 3D scatter plot which is much easier, but won't get you the kind of plot you asked for (https://matplotlib.org/examples/mplot3d/scatter3d_demo.html)

Related

How to set camera angle of a 2D plot in matplotlib?

I have generated a series of 2D plots using matplotlib.pyplot. I want to change the perspective of each 2D plot to make them look more "3D" (from the rectangular shape to parallelogram shape) and stack them together by hand, which will look something like this:
If there are texts present in the 2D plot (e.g. labels, title, legend), I want them to be rotated together with the plot. The reason I don't want to use mplot3d is that it doesn't support some advanced functions that is used in my 2D plots.
This has already been asked before for 3D plots: how to set "camera position" for 3d plots using python/matplotlib?, but the ax.view_init is only implemented for 3D plots. I wonder if there is a way to also change the camera angle for a 2D plot. If not, are there any tools that can do this task?

How to create 3d pcolormesh of array values?

I have data that occurs in an arrays at x(0:127), y(0:127), and z(0:98). For example, at the coordinates of x=23, y=27, and z=76 the data value might be 826. How can I create a 3d pcolorrmesh of these values to look similar to the link provided:
I don't think you can use pcolormesh for 3D plots. However look here for the official matplotlib tutorial on 3D plottting.

Maplotlib 3d imshow

I have a 3d array of data of which I am trying to do a visualization. The entries of the 3d array can only take boolean value. I would like to visualize it in way imshow offers to visualize a matrix by giving a color value to each entry. Here it is in 3d so I guess we should add some empty space between the points to see the inside.
I have looked into matplotlib 3d plots but I could not find the right tool for such visualization. What could I use?

Plotting 2D satellite profile data in 3D over earth projection in Python

I am attempting to do something similar to this:
sample ozone profile
Not necessarily over an orthographic projection - a cube over a map would suffice.
I'm able to plot the PolyCollection object produced by matplotlib.pyplot.pcolor, but cannot figure out if there's an accepted way of plotting the profile over an arbitrary lat/lon path.
The only thing I can think of right now is continuing to use pcolor() to get the face colors, then just modifying the vertices for each Poly object.
If you want to create a 3D projection, then you may use the plot_surface. It essentially draws a 2D array where the 3D coordinates of each vertex is given.
You might get some ideas by looking at this: Creating intersecting images in matplotlib with imshow or other function
The matplotlib solution there is essentially the same as using pcolor, but the 3D arithmetics is carried out by matplotlib. The suggestion to use mayavi is also something worth conisdering, as matplotlib is not at its strongest with 3D projected raster data.

How to display a float matrix as elevation values in a 3D plot in Python?

I currently have a heat map which is a 2D float matrix (list of lists of floats to be accurate), and I can display it in 2D with matplotlib fairly easily, but I would like to display it in a 3D plot such that the column and row indices can by the X and Y values respectively, and the values in the matrix are Z (elevation) values. What can I use to do that? I tried using Axes3D but it didn't seem very suitable (or maybe I was using it wrong?). What I am looking to do is conceptually very simple, to pretend the matrix is a DEM and display it as such.
Also if possible I would like to be able to change viewing angles on-the-fly, without having to re-generate the plot.
Any ideas?
These two questions are related but don't quite answer my question:
3d plotting with python
Python: 3D contour from a 2D image - pylab and contourf
NB: The float matrix is rather large, typically 100x100 or more, and the last time I tried to plot it in 3D my system ran out of memory and started thrashing.
Your use case seems like it is tailor made for mayavi/mlab, which has a function that does exactly what you are asking and by default permits interactive 3D rotation:
import numpy as np; from mayavi import mlab
data = np.random.random((100,100))
mlab.surf(data)
mlab.show()

Categories

Resources