Skip to content
Advertisement

Surface plot for the profile

I am trying to plot the surface profile but I am getting this only. I don’t know why it’s not plotting the surface profile. Where is the mistake?

enter image description here

Where am I going wrong ? I have already mentioned all the axes but all I am getting is the above figure. Can anybody help in figuring it out?

dis=[10,40]
b=0
f=25/60
time=20
t_i=0.001
mean=0.03
std=0.00666
r=0.2
w=2*np.pi*200/60
v=2*np.pi*r*200/60
avg=0.03
high=2
xm=np.linspace(0,2,500)
ym=high
# fig,ax=plt.subplots(figsize=(12,2))
ax=fig.add_subplot(projection='3d')
for b in range(len(dis)):
    n=2*3.14*dis[b]*r/(avg*100)
    s=np.random.normal(mean,std,round(n))
    
    for i in s:   
        t=np.arange(0.1,time,t_i) 
        k=r+i
        c=v/k
        m=np.sqrt((k**2-(k-0.01)**2)/k)
        j=np.arcsin(m)
        x=k*(np.sin((c*t)+j))+f*t
        y=k*(np.cos((c*t)+j))
        ax.set_xlim([0.3,2])
        ax.set_ylim([y.min()-0.05,-0.1])
        reversed = False
        ind0=0
        while ind0 < len(x):
            ind1 = ind0 + 1
            if reversed:
                while ind1 < len(x) and x[ind1] <= x[ind1 - 1]:
                    ind1 += 1
                ym = np.minimum(ym, np.interp(xm, x[ind0:ind1][::-1], y[ind0:ind1][::-1], left=high, right=high))
            else:
                while ind1 < len(x) and x[ind1] >= x[ind1 - 1]:
                    ind1 += 1
                ym=np.minimum(ym, np.interp(xm, x[ind0:ind1], y[ind0:ind1], left=high, right=high))
            ind0 = ind1
            reversed = not reversed
    
    Y=np.linspace(0,30,200)
    z=np.outer(ym[:200],np.ones(200))
    xs,ys=np.meshgrid(xm[:200],Y)
    fig=plt.figure(figsize=(15,8))
    ax.set_xlabel('x (mm)')
    ax.set_ylabel('y (mm)')
    ax.plot_surface(xs, ys,z,cmap='viridis')

Advertisement

Answer

You are creating an ax object before you have created a fig object, while you are creating new fig objects inside of your for loop. Move the creation of fig outside of the for loop.

dis=[10,40]
b=0
f=25/60
time=20
t_i=0.001
mean=0.03
std=0.00666
r=0.2
w=2*np.pi*200/60
v=2*np.pi*r*200/60
avg=0.03
high=2
xm=np.linspace(0,2,500)
ym=high
# fig,ax=plt.subplots(figsize=(12,2))
fig=plt.figure(figsize=(15,8))
ax=fig.add_subplot(projection='3d')
for b in range(len(dis)):
    n=2*3.14*dis[b]*r/(avg*100)
    s=np.random.normal(mean,std,round(n))
    
    for i in s:   
        t=np.arange(0.1,time,t_i) 
        k=r+i
        c=v/k
        m=np.sqrt((k**2-(k-0.01)**2)/k)
        j=np.arcsin(m)
        x=k*(np.sin((c*t)+j))+f*t
        y=k*(np.cos((c*t)+j))
        # ax.set_xlim([0.3,2])
        # ax.set_ylim([y.min()-0.05,-0.1])
        reversed = False
        ind0=0
        while ind0 < len(x):
            ind1 = ind0 + 1
            if reversed:
                while ind1 < len(x) and x[ind1] <= x[ind1 - 1]:
                    ind1 += 1
                ym = np.minimum(ym, np.interp(xm, x[ind0:ind1][::-1], y[ind0:ind1][::-1], left=high, right=high))
            else:
                while ind1 < len(x) and x[ind1] >= x[ind1 - 1]:
                    ind1 += 1
                ym=np.minimum(ym, np.interp(xm, x[ind0:ind1], y[ind0:ind1], left=high, right=high))
            ind0 = ind1
            reversed = not reversed
    
    Y=np.linspace(0,30,200)
    z=np.outer(ym[:200],np.ones(200))
    xs,ys=np.meshgrid(xm[:200],Y)
    ax.set_xlabel('x (mm)')
    ax.set_ylabel('y (mm)')
    ax.plot_surface(xs, ys,z,cmap='viridis')

surface plot

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement