3D Surface

Klein Bottle Immersion

Non-orientable surface immersed in 3D space - a topological curiosity.

Output
Klein Bottle Immersion
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

colors = ['#0a0a0f', '#1e1b4b', '#4f46e5', '#818cf8', '#c7d2fe']
cmap = LinearSegmentedColormap.from_list('electric', colors, N=256)

u = np.linspace(0, 2*np.pi, 80)
v = np.linspace(0, 2*np.pi, 80)
U, V = np.meshgrid(u, v)

# Figure-8 Klein bottle immersion
r = 2
X = (r + np.cos(U/2)*np.sin(V) - np.sin(U/2)*np.sin(2*V)) * np.cos(U)
Y = (r + np.cos(U/2)*np.sin(V) - np.sin(U/2)*np.sin(2*V)) * np.sin(U)
Z = np.sin(U/2)*np.sin(V) + np.cos(U/2)*np.sin(2*V)

fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')

surf = ax.plot_surface(X, Y, Z, cmap=cmap, linewidth=0, antialiased=True, alpha=0.9)

ax.set_xlabel('X', color='white', fontsize=10)
ax.set_ylabel('Y', color='white', fontsize=10)
ax.set_zlabel('Z', color='white', fontsize=10)
ax.set_title('Klein Bottle Immersion', color='white', fontsize=14, fontweight='bold', pad=20)

ax.tick_params(colors='#64748b', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#1e293b')
ax.yaxis.pane.set_edgecolor('#1e293b')
ax.zaxis.pane.set_edgecolor('#1e293b')

ax.view_init(elev=25, azim=45)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support