pythonmeshsurf

Plotting a curve on the mesh surface along only a determined axis


I'm very new in Python and trying to plot a single curve on a surface.

Here is where I came so far and plotted a surface in s domain:

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

x = np.linspace(-400, 0, 100)
y = np.linspace(-100, 100, 100)

X, Y = np.meshgrid(x,y)

fc=50
wc=2*np.pi*fc

s = X + Y*1j
Z= abs(1/(1+s/wc))

fig = plt.figure()
ax = fig.gca(projection='3d')

surf = ax.plot_surface(X, Y, Z)

ax.plot(X, Y, Z)
plt.ylabel('Im')
plt.show()

enter image description here

I now need to plot the curve for X = 0 in different color which means the curve on the same surface along the imaginary axis. surf = ax.plot_surface(0, Y, Z) did not work. Does anybody have experience with such plot?


Solution

  • I'm assuming you meant you wanted to plot y=0 instead of x=0 (since x=0 would be pretty boring).

    Since you want to plot a single slice of your data, you can't use the meshgrid format (or if you can, it would require some weird indexing that I don't want to figure out).

    Here's how I would plot the y=0 slice:

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import cmath
    
    x = np.linspace(-400, 0, 100)
    y = np.linspace(-100, 100, 100)
    
    X, Y = np.meshgrid(x,y)
    
    fc=50
    wc=2*np.pi*fc
    
    s = X + Y*1j
    Z= abs(1/(1+s/wc))
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    
    surf = ax.plot_surface(X, Y, Z)
    
    # create data for y=0
    z = abs(1/(1+x/wc))
    ax.plot(x,np.zeros(np.shape(x)),z)
    
    plt.ylabel('Im')
    plt.show()
    

    enter image description here