I have a 3D graph like below:
3D graph
Ref: google images

It has 2 angles as X and Y and the Z axis is amplitude value (Each 3D graph is representing a pixel). I want to model this into some useful data structure like a graph or a vector considering some parameters extracted from the above 3D graph, so that I'll be able to feed it into a classification algorithm. But, I'm unable to extract all the local minimas/maximas, or slopes. How do I do it using in python? I'm not exactly asking for code (libraries and code will be definitely appreciated) but rather the methodologies used.

Can I use Machine learning to extract certain parameters from the graph?

I'm really new to this and I don't even know how to exactly frame the question, so I do apologise for low quality question. Please point me towards something so that I can look and read from there.


2 Answers 2


You are describing different coordinates but suppose for a second that points are represented as cartesian coordinates $(x,y,z)$. A surface consists of infinitely many points which cannot be stored by a computer. One solution to this problem is that we put a grid over the $(x,y)$-plane and store for each point in the grid the height value $z$. Here, is an easy example in python

from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt

# create grid for (x,y)-plane
x = np.outer(np.linspace(-2, 2, 30), np.ones(30))
y = x.copy().T

# heigt of the function at each point in the grid
z = x ** 2 + y ** 2

# plot it
fig = plt.figure()
ax = plt.axes(projection='3d')

ax.plot_surface(x, y, z,cmap='viridis', edgecolor='none')
ax.set_title('Surface plot')

This is why you have a grid over the surface in your image. Note that we can make the grid very tight or very loose. The image you get is usually an approximation except for the case that the surface is a plane.

If you use two angles and a distance to represent the points you are using spherical coordinates.

Now, you have got a finite representation of your surface that you can use in a classification algorithm. Regarding local minima/maxima, or slopes. If you got a formula like $z = x^2 + y^2$ you can calculate them using some maths.

Other situation: Suppose you only got three lists as in the code example and you don't know how $z$ is generated. Now, there are infinitely many surfaces that go through these points. The simplest way is to fill the space linearly, i.e. you take three points and draw triangles to connect them. In this case you can find minima algorithmically. For example, the global minimum is at the point of your grid with lowest height. A point in your grid is a local minimum if all the neighbouring points have a greater height.

  • $\begingroup$ I already have the surface in terms of 50k points. I want to characterize it. $\endgroup$ Commented Jul 7, 2021 at 11:18
  • $\begingroup$ Also, I have mechanism for generating z. So, think of it this way. I want to figure out the relation between them and assign them a class for that particular relation. Which then I'll use for classification. $\endgroup$ Commented Jul 7, 2021 at 11:18
  • $\begingroup$ I'm not trying to create a graph. I have the data to generate a graph and the graph. What I'm trying to do is extract certain parameters of the graph as such. Something like local minima. I can parse the data I have to generate the graph to get absolute minima but the graph has many inflection points and I don't know how to get access to them as this is not a defined function and I get output from a physical world scenario. $\endgroup$ Commented Jul 7, 2021 at 11:22
  • $\begingroup$ For local minima see last sentence in my answer. infliction points: There are 4 lines from each inner point in your grid leading to 4 neighbouring points. For an infliction point two facing neighbouring points must have a greater height while the other two must have lower height. $\endgroup$
    – Philipp
    Commented Jul 7, 2021 at 11:36
  • $\begingroup$ Hmmm. Okay. What about slope? I calculate in desired direction with neighbour points. $\endgroup$ Commented Jul 7, 2021 at 11:47

You need to fit a model. The model depends on what the graph looks like - constraints, smoothness , shape etc.

A simple model might be a mixture of Gaussians,

Z=sum( ai * exp( 
  /si ) )

Where xi yi si ai are free parameters for each gaussian. If you have 4 bumps on the plot, you might want 4 gaussians. You can create a function

def modelz(x,y,params)

Where params is a vector containing all the xi yi ai si. Then use maximum likelihood to fit it

def loss(params)
   sum( Z-model(X ,Y, params) )**2

Where capital XYZ are the data. And minimise this

p1 = minimize( loss, p0 )

Where p0 is an initial guess. p1 is then a representation of the surface.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.