I use matplotlib plot_surface() function and plot a complex function in 3D. Here is my code:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
point_num = 200
x = np.linspace(-5, 3, point_num)
y = np.linspace(-5, 5, point_num)
# Real axis and imaginary axis-----------------------------
Re, Im = np.meshgrid(x, y)
#----------------------------------------------------------
# here is the complex function I need evaluate-------------
z = Re + Im * 1j
R3 = 1 + z + 1/2 * z**2 + 1/6 * pow(z, 3)
#----------------------------------------------------------
# my 3d surface plot----------------------------------------
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(Re, Im, np.abs(R1))
ax.set_xlabel("Im(z)")
ax.set_ylabel("Re(z)")
ax.set_zlabel('R(z)')
plt.show()
#----------------------------------------------------------
I can successfully get the surface plot:
The surface looks like a cone. Now I want to "slice" the cone with plane R(z)=1 and get a 2D contour plot. I can get the contour on the 3D surface like this:
ax.contour(Re, Im, np.abs(R3), [1], colors='r')
I want to plot the red line contour in an independent 2D plot. It should be in the real and imaginary axis. Moreover, can we get the coordinates of the intersection points of the contour line with the axis? Like the figure below:
Thank you very much!


