[Python] How can I plot two helicoids without a jump between surfaces?

Discussão em 'Python' iniciado por Stack, Outubro 25, 2024.

  1. Stack

    Stack Membro Participativo

    Using matplotlib surface plot, I am plotting two right, helicoids. I have the surfaces as a single mesh however this makes an unwanted jump between the two surfaces.

    Helicoid pair with jumps and poor surface face colormap: [​IMG]

    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt

    u = np.linspace(-np.pi, np.pi, 200)
    v = np.linspace(np.pi, -np.pi, 200)

    theta = np.pi
    U, V = np.meshgrid(u, v)

    X = np.cos(theta)*np.sinh(V)*np.sin(U) + np.sin(theta)*np.cosh(V)*np.cos(U)
    Y = -np.cos(theta)*np.sinh(V)*np.cos(U) + np.sin(theta)*np.cosh(V)*np.sin(U)
    Z = U*np.cos(theta)+V*np.sin(theta)


    i = -1
    for j in np.linspace(0,.8, 2):
    X = np.append(X, X[::i,:], axis = 0)
    Y = np.append(Y, Y[::i,:], axis = 0)
    Z = np.append(Z, Z[::i,:]+j, axis = 0)
    i *=-1

    r_cols = (X**2 + Y**2)
    r_cols /= np.max(r_cols)
    r_cols = cm.jet(r_cols)


    fig, ax = plt.subplots(figsize=(5,5), subplot_kw={"projection": "3d"})


    ax.plot_surface(X, Y, Z, vmin=Z.min() * 2, facecolors = r_cols, rstride = 1 , linewidth=0 )

    ax.set(xticklabels=[],
    yticklabels=[],
    zticklabels=[])
    ax.view_init(elev=5, azim=40, roll=0)

    plt.show()
    fig.savefig('file{}.png'.format(num))
    num +=1


    I have tried to stack u to route back to the helical axis such as:

    u = np.append(np.linspace(0, -np.pi, 200), np.linspace(-np.pi, np.pi, 200))
    u = np.append(u,np.linspace(np.pi,0, 200))


    as well as changing the way I stacked and added to Z

    invert = -1
    revert = 1
    for j in np.linspace(0,.8, 2):
    X = np.append(X, X[::invert,::revert], axis = 0)
    Y = np.append(Y, Y[::invert,::revert], axis = 0)
    Z = np.append(Z, Z[::invert,::revert]+j, axis = 0)
    invert *=-1
    revert *=-1

    Continue reading...

Compartilhe esta Página