3

I want to plot the surface graph and minimum point as follows:

enter image description here

I have tried to make python code:

import sympy
import numpy
from numpy import linalg
from numpy import linspace
from sympy import lambdify
import matplotlib.pyplot as plt
from matplotlib import cm
x1,x2=sympy.symbols('x1 x2')
f=x1**2-x1*x2-4*x1+x2**2-x2
lam_f = lambdify([x1,x2], f, modules=['numpy'])
x1value=linspace(-6,6,50)
x2value=linspace(-6,6,50)
x1value, x2value = numpy.meshgrid(x1value, x2value)
fvalue=lam_f(x1value,x2value)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
surf = ax.plot_surface(x1value, x2value, fvalue, cmap=cm.jet,linewidth=0, antialiased=False,label="$f(x_1,x_2)$")
ax.set_xlabel('$x_1$')
ax.set_ylabel('$x_2$')
ax.set_zlabel('$f(x_1,x_2)$')
ax.scatter(3,2,-7,color="cyan",s=50,marker="s",zorder=2,linewidths=2)
plt.show()

enter image description here

enter image description here

The minimum point cannot see from above, but from below we can see the minimum point.

I want minimum point can see from above as the first picture. How to make it?

  • You could always decrease the opacity of your `ax.plot_surface` by using `alpha=0.3` for instance. See example [here](https://stackoverflow.com/questions/70511417/scatter-points-are-disappearing-when-rotating-a-3d-surface-plot/70527465#70527465) – jylls Jan 22 '22 at 02:53
  • I do not want the surface is transparent. – Ongky Denny Wijaya Jan 22 '22 at 05:04

0 Answers0