How to find peaks in python for a 3D plot? - python

I have plotted a 3D radiation plot using Python, with theta on the x-axis and phi on the y-axis and magnitudes along z. I initially used numpy.meshgrid to create the 2d array for thetas and phis. Now how can I find the peak points( main lobe and side lobes) from this graph?
find_peak function of the scipy.signal library seems to deal with 1d array only.

Try to use maximum_filter from scipy.ndimage.filters, or even just a simple thresholding could do the trick, provided prior smoothing/transformations like erosion/dilation.

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?

slicing volume rendering graph in 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)

plotting 2D slice of arbitrary orientation through 3D data in matplotlib

I have a 3D regular grid of data. I would like to write a routine allowing the user to specify a plane slicing through the data with arbitrary orientation and returning a contour plot of the data in the plane. Is there a ready-made way in matplotlib to do this? Could find anything in the docs.
You can use roll function of numpy to rotate your plane and make it parallel with a base plane. now you can choose your plane and plot. Only problem is that at close to edges the value from one side will be added to opposite side.

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